From e0e95c11761e1f90d56db64369f9347842d79d1e Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Thu, 5 Oct 2023 14:55:09 -0600 Subject: [PATCH 01/18] Add trino adapter support for MetricFlow --- Makefile | 3 + dbt-metricflow/pyproject.toml | 3 + .../dbt_connectors/adapter_backed_client.py | 6 + metricflow/protocols/sql_client.py | 1 + metricflow/sql/render/trino.py | 115 ++ .../metricflow_testing/profiles.yml | 11 + metricflow/test/fixtures/setup_fixtures.py | 1 + .../test/fixtures/sql_client_fixtures.py | 15 + .../sql_clients/adapter_backed_ddl_client.py | 4 + .../fixtures/sql_clients/common_client.py | 1 + ...st_convert_query_semantic_model__plan0.sql | 30 + ...le_semantic_model_with_measures__plan0.sql | 57 + ...semantic_model_without_measures__plan0.sql | 30 + .../Trino/test_build_metric_tasks__query0.sql | 17 + .../test_combined_metrics_plan__ep_0.xml | 89 ++ .../Trino/test_joined_plan__ep_0.xml | 34 + .../Trino/test_multihop_joined_plan__ep_0.xml | 42 + ...test_small_combined_metrics_plan__ep_0.xml | 49 + .../test_common_semantic_model__plan0.sql | 467 +++++++ ...common_semantic_model__plan0_optimized.sql | 42 + .../test_compute_metrics_node__plan0.sql | 202 +++ ..._compute_metrics_node__plan0_optimized.sql | 23 + ...o_from_multiple_semantic_models__plan0.sql | 748 ++++++++++++ ...tiple_semantic_models__plan0_optimized.sql | 82 ++ ...atio_from_single_semantic_model__plan0.sql | 205 ++++ ...single_semantic_model__plan0_optimized.sql | 31 + ...ompute_metrics_node_simple_expr__plan0.sql | 202 +++ ...rics_node_simple_expr__plan0_optimized.sql | 21 + .../test_constrain_time_range_node__plan0.sql | 119 ++ ...train_time_range_node__plan0_optimized.sql | 11 + .../Trino/test_cumulative_metric__plan0.sql | 94 ++ ...est_cumulative_metric__plan0_optimized.sql | 12 + ...cumulative_metric_grain_to_date__plan0.sql | 94 ++ ..._metric_grain_to_date__plan0_optimized.sql | 12 + .../test_cumulative_metric_no_ds__plan0.sql | 89 ++ ...mulative_metric_no_ds__plan0_optimized.sql | 9 + ...est_cumulative_metric_no_window__plan0.sql | 94 ++ ...tive_metric_no_window__plan0_optimized.sql | 12 + ..._no_window_with_time_constraint__plan0.sql | 138 +++ ..._with_time_constraint__plan0_optimized.sql | 14 + ...ive_metric_with_time_constraint__plan0.sql | 138 +++ ..._with_time_constraint__plan0_optimized.sql | 14 + .../Trino/test_derived_metric__plan0.sql | 479 ++++++++ .../test_derived_metric__plan0_optimized.sql | 59 + ...ved_metric_with_offset_to_grain__plan0.sql | 585 +++++++++ ..._with_offset_to_grain__plan0_optimized.sql | 63 + ...offset_to_grain_and_granularity__plan0.sql | 586 +++++++++ ...grain_and_granularity__plan0_optimized.sql | 64 + ...rived_metric_with_offset_window__plan0.sql | 585 +++++++++ ...ic_with_offset_window__plan0_optimized.sql | 63 + ...h_offset_window_and_granularity__plan0.sql | 585 +++++++++ ...indow_and_granularity__plan0_optimized.sql | 63 + ...fset_window_and_offset_to_grain__plan0.sql | 691 +++++++++++ ...w_and_offset_to_grain__plan0_optimized.sql | 67 + ...offset_to_grain_and_granularity__plan0.sql | 692 +++++++++++ ...grain_and_granularity__plan0_optimized.sql | 68 ++ ...erived_offset_cumulative_metric__plan0.sql | 460 +++++++ ...set_cumulative_metric__plan0_optimized.sql | 34 + ...et_metric_with_one_input_metric__plan0.sql | 339 ++++++ ...with_one_input_metric__plan0_optimized.sql | 27 + .../Trino/test_distinct_values__plan0.sql | 404 ++++++ .../test_distinct_values__plan0_optimized.sql | 19 + .../Trino/test_filter_node__plan0.sql | 103 ++ .../test_filter_node__plan0_optimized.sql | 6 + ...lter_with_where_constraint_node__plan0.sql | 111 ++ ...where_constraint_node__plan0_optimized.sql | 14 + ...th_where_constraint_on_join_dim__plan0.sql | 409 +++++++ ...onstraint_on_join_dim__plan0_optimized.sql | 35 + .../test_join_to_scd_dimension__plan0.sql | 334 +++++ ...join_to_scd_dimension__plan0_optimized.sql | 47 + ...spine_node_with_offset_to_grain__plan0.sql | 247 ++++ ..._with_offset_to_grain__plan0_optimized.sql | 36 + ...e_spine_node_with_offset_window__plan0.sql | 247 ++++ ...de_with_offset_window__plan0_optimized.sql | 36 + ..._time_spine_node_without_offset__plan0.sql | 247 ++++ ...e_node_without_offset__plan0_optimized.sql | 36 + .../Trino/test_limit_rows__plan0.sql | 234 ++++ .../test_limit_rows__plan0_optimized.sql | 19 + ...al_dimension_using_local_entity__plan0.sql | 160 +++ ...on_using_local_entity__plan0_optimized.sql | 17 + .../test_measure_aggregation_node__plan0.sql | 114 ++ ...sure_aggregation_node__plan0_optimized.sql | 10 + .../Trino/test_measure_constraint__plan0.sql | 1083 +++++++++++++++++ ...st_measure_constraint__plan0_optimized.sql | 110 ++ ..._constraint_with_reused_measure__plan0.sql | 495 ++++++++ ...t_with_reused_measure__plan0_optimized.sql | 53 + ...aint_with_single_expr_and_alias__plan0.sql | 249 ++++ ...single_expr_and_alias__plan0_optimized.sql | 28 + ..._multiple_sources_no_dimensions__plan0.sql | 390 ++++++ ...sources_no_dimensions__plan0_optimized.sql | 26 + ...multi_hop_through_scd_dimension__plan0.sql | 488 ++++++++ ...through_scd_dimension__plan0_optimized.sql | 52 + ...test_multi_hop_to_scd_dimension__plan0.sql | 467 +++++++ ..._hop_to_scd_dimension__plan0_optimized.sql | 55 + .../Trino/test_multi_join_node__plan0.sql | 260 ++++ .../test_multi_join_node__plan0_optimized.sql | 37 + .../Trino/test_multihop_node__plan0.sql | 388 ++++++ .../test_multihop_node__plan0_optimized.sql | 35 + ..._multiple_metrics_no_dimensions__plan0.sql | 572 +++++++++ ...metrics_no_dimensions__plan0_optimized.sql | 30 + .../test_nested_derived_metric__plan0.sql | 971 +++++++++++++++ ...nested_derived_metric__plan0_optimized.sql | 131 ++ ...st_offset_window_with_date_part__plan0.sql | 585 +++++++++ ...window_with_date_part__plan0_optimized.sql | 63 + .../Trino/test_order_by_node__plan0.sql | 130 ++ .../test_order_by_node__plan0_optimized.sql | 21 + .../Trino/test_partitioned_join__plan0.sql | 259 ++++ ...test_partitioned_join__plan0_optimized.sql | 29 + .../test_semi_additive_join_node__plan0.sql | 112 ++ ...mi_additive_join_node__plan0_optimized.sql | 78 ++ ...dditive_join_node_with_grouping__plan0.sql | 119 ++ ...in_node_with_grouping__plan0_optimized.sql | 85 ++ ...join_node_with_queried_group_by__plan0.sql | 115 ++ ...with_queried_group_by__plan0_optimized.sql | 81 ++ ...est_simple_query_with_date_part__plan0.sql | 227 ++++ ..._query_with_date_part__plan0_optimized.sql | 17 + ..._query_with_multiple_date_parts__plan0.sql | 258 ++++ ...h_multiple_date_parts__plan0_optimized.sql | 42 + .../Trino/test_single_join_node__plan0.sql | 184 +++ ...test_single_join_node__plan0_optimized.sql | 17 + .../Trino/test_source_node__plan0.sql | 97 ++ .../test_source_node__plan0_optimized.sql | 97 ++ ...mate_continuous_percentile_expr__plan0.sql | 4 + .../Trino/test_cast_to_timestamp__plan0.sql | 4 + .../Trino/test_generate_uuid__plan0.sql | 4 + ...orm_node_using_non_primary_time__plan0.sql | 194 +++ ...sing_non_primary_time__plan0_optimized.sql | 97 ++ ...ansform_node_using_primary_time__plan0.sql | 206 ++++ ...de_using_primary_time__plan0_optimized.sql | 109 ++ ...uery_with_metric_time_dimension__plan0.sql | 455 +++++++ ...metric_time_dimension__plan0_optimized.sql | 42 + .../Trino/test_render_query__query0.sql | 17 + ...st_render_write_to_table_query__query0.sql | 19 + .../Trino/test_component_rendering__plan0.sql | 4 + .../Trino/test_component_rendering__plan1.sql | 6 + .../Trino/test_component_rendering__plan2.sql | 10 + .../Trino/test_component_rendering__plan3.sql | 14 + .../Trino/test_component_rendering__plan4.sql | 16 + .../Trino/test_component_rendering__plan5.sql | 17 + .../Trino/test_render_limit__plan0.sql | 5 + .../Trino/test_render_order_by__plan0.sql | 6 + .../Trino/test_render_where__plan0.sql | 5 + pyproject.toml | 21 + 143 files changed, 21567 insertions(+) create mode 100644 metricflow/sql/render/trino.py create mode 100644 metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql create mode 100644 metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql create mode 100644 metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql create mode 100644 metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml create mode 100644 metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml create mode 100644 metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml create mode 100644 metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql create mode 100644 metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql create mode 100644 metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql create mode 100644 metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql create mode 100644 metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql diff --git a/Makefile b/Makefile index 41eb3d1d16..92dfc2a12a 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,9 @@ test-snowflake: populate-persistent-source-schema-snowflake: hatch -v run snowflake-env:pytest -vv $(ADDITIONAL_PYTEST_OPTIONS) $(USE_PERSISTENT_SOURCE_SCHEMA) $(POPULATE_PERSISTENT_SOURCE_SCHEMA) +.PHONY: test-trino +test-trino: + hatch -v run trino-env:pytest -vv -n $(PARALLELISM) $(ADDITIONAL_PYTEST_OPTIONS) metricflow/test/ .PHONY: lint lint: diff --git a/dbt-metricflow/pyproject.toml b/dbt-metricflow/pyproject.toml index 99ac4043d4..eb1a71794f 100644 --- a/dbt-metricflow/pyproject.toml +++ b/dbt-metricflow/pyproject.toml @@ -50,6 +50,9 @@ redshift = [ snowflake = [ "dbt-snowflake~=1.7.0" ] +trino = [ + "dbt-trino~=1.6.0" +] [tool.hatch.build.targets.sdist] exclude = [ diff --git a/metricflow/cli/dbt_connectors/adapter_backed_client.py b/metricflow/cli/dbt_connectors/adapter_backed_client.py index 09180aabca..c9c6fe7b05 100644 --- a/metricflow/cli/dbt_connectors/adapter_backed_client.py +++ b/metricflow/cli/dbt_connectors/adapter_backed_client.py @@ -21,6 +21,7 @@ from metricflow.sql.render.redshift import RedshiftSqlQueryPlanRenderer from metricflow.sql.render.snowflake import SnowflakeSqlQueryPlanRenderer from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer +from metricflow.sql.render.trino import TrinoSqlQueryPlanRenderer from metricflow.sql.sql_bind_parameters import SqlBindParameters from metricflow.sql_request.sql_request_attributes import SqlJsonTag, SqlRequestId, SqlRequestTagSet from metricflow.sql_request.sql_statement_metadata import CombinedSqlTags, SqlStatementCommentMetadata @@ -42,6 +43,7 @@ class SupportedAdapterTypes(enum.Enum): REDSHIFT = "redshift" BIGQUERY = "bigquery" DUCKDB = "duckdb" + TRINO = "trino" @property def sql_engine_type(self) -> SqlEngine: @@ -58,6 +60,8 @@ def sql_engine_type(self) -> SqlEngine: return SqlEngine.SNOWFLAKE elif self is SupportedAdapterTypes.DUCKDB: return SqlEngine.DUCKDB + elif self is SupportedAdapterTypes.TRINO: + return SqlEngine.TRINO else: assert_values_exhausted(self) @@ -76,6 +80,8 @@ def sql_query_plan_renderer(self) -> SqlQueryPlanRenderer: return SnowflakeSqlQueryPlanRenderer() elif self is SupportedAdapterTypes.DUCKDB: return DuckDbSqlQueryPlanRenderer() + elif self is SupportedAdapterTypes.TRINO: + return TrinoSqlQueryPlanRenderer() else: assert_values_exhausted(self) diff --git a/metricflow/protocols/sql_client.py b/metricflow/protocols/sql_client.py index 8497002559..b9e9588ac4 100644 --- a/metricflow/protocols/sql_client.py +++ b/metricflow/protocols/sql_client.py @@ -23,6 +23,7 @@ class SqlEngine(Enum): POSTGRES = "Postgres" SNOWFLAKE = "Snowflake" DATABRICKS = "Databricks" + TRINO = "Trino" class SqlClient(Protocol): diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py new file mode 100644 index 0000000000..b08e217268 --- /dev/null +++ b/metricflow/sql/render/trino.py @@ -0,0 +1,115 @@ +from __future__ import annotations + +from typing import Collection + +from dbt_semantic_interfaces.enum_extension import assert_values_exhausted +from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity +from typing_extensions import override + +from metricflow.sql.render.expr_renderer import ( + DefaultSqlExpressionRenderer, + SqlExpressionRenderer, + SqlExpressionRenderResult, +) +from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer +from metricflow.sql.sql_bind_parameters import SqlBindParameters +from metricflow.sql.sql_exprs import ( + SqlCastToTimestampExpression, + SqlGenerateUuidExpression, + SqlPercentileExpression, + SqlPercentileFunctionType, + SqlTimeDeltaExpression, +) + +class TrinoSqlExpressionRenderer(DefaultSqlExpressionRenderer): + """Expression renderer for the Trino engine.""" + + @property + @override + def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctionType]: + return { + SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS, + } + + @override + def visit_cast_to_timestamp_expr(self, node: SqlCastToTimestampExpression) -> SqlExpressionRenderResult: + """Casts the time value expression to timestamp. + + Trino's TIMESTAMP type requires timezone inputs to convert to and from different formats, whereas its + DATETIME data type does not. This is different from Databricks, which simply returns and renders inUTC by + default, or Snowflake which does something user-configurable but defaults to TIMESTAMP_NTZ, or PostgreSQL, + which adheres to the SQL standard of TIMESTAMP_NTZ. + """ + arg_rendered = self.render_sql_expr(node.arg) + return SqlExpressionRenderResult( + sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type})", + bind_parameters=arg_rendered.bind_parameters, + ) + + @override + def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult: + """Render time delta expression for Trino, which requires slightly different syntax from other engines.""" + arg_rendered = node.arg.accept(self) + if node.grain_to_date: + return SqlExpressionRenderResult( + sql=f"DATE_TRUNC('{node.granularity.value}', {arg_rendered.sql}::timestamp)", + bind_parameters=arg_rendered.bind_parameters, + ) + + count = node.count + granularity = node.granularity + if granularity == TimeGranularity.QUARTER: + granularity = TimeGranularity.MONTH + count *= 3 + + return SqlExpressionRenderResult( + sql=f"{arg_rendered.sql} - INTERVAL {count} {granularity.value}", + bind_parameters=arg_rendered.bind_parameters, + ) + + @override + def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpressionRenderResult: + return SqlExpressionRenderResult( + sql="uuid()", + bind_parameters=SqlBindParameters(), + ) + + @override + def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionRenderResult: + """Render a percentile expression for Trino.""" + arg_rendered = self.render_sql_expr(node.order_by_arg) + params = arg_rendered.bind_parameters + percentile = node.percentile_args.percentile + + if node.percentile_args.function_type is SqlPercentileFunctionType.CONTINUOUS: + function_str = "PERCENTILE_CONT" + elif node.percentile_args.function_type is SqlPercentileFunctionType.DISCRETE: + function_str = "PERCENTILE_DISC" + elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS: + return SqlExpressionRenderResult( + sql=f"approx_quantile({arg_rendered.sql}, {percentile})", + bind_parameters=params, + ) + elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_DISCRETE: + raise RuntimeError( + "Approximate discrete percentile aggregatew not supported for Trino. Set " + + "use_discrete_percentile and/or use_approximate_percentile to false in all percentile measures." + ) + else: + assert_values_exhausted(node.percentile_args.function_type) + + return SqlExpressionRenderResult( + sql=f"{function_str}({percentile}) WITHIN GROUP (ORDER BY ({arg_rendered.sql}))", + bind_parameters=params, + ) + + +class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer): + """Plan renderer for the Trino engine.""" + + EXPR_RENDERER = TrinoSqlExpressionRenderer() + + @property + @override + def expr_renderer(self) -> SqlExpressionRenderer: + return self.EXPR_RENDERER \ No newline at end of file diff --git a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml index 3285cb836b..ca06dd4f57 100644 --- a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml +++ b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml @@ -67,3 +67,14 @@ duckdb: dev: type: duckdb schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}" +trino: + target: dev + outputs: + dev: + type: trino + host: "{{ env_var('DBT_ENV_SECRET_HOST') }}" + port: "{{ env_var('DBT_PROFILE_PORT') | int }}" + user: "{{ env_var('DBT_ENV_SECRET_USER') }}" + password: "{{ env_var('DBT_ENV_SECRET_PASSWORD') }}" + catalog: "{{ env_var('DBT_ENV_SECRET_CATALOG') }}" + schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}" \ No newline at end of file diff --git a/metricflow/test/fixtures/setup_fixtures.py b/metricflow/test/fixtures/setup_fixtures.py index 9c936d0f22..2109dbc506 100644 --- a/metricflow/test/fixtures/setup_fixtures.py +++ b/metricflow/test/fixtures/setup_fixtures.py @@ -20,6 +20,7 @@ logger = logging.getLogger(__name__) + @dataclass class MetricFlowTestSessionState: """State that is shared between tests during a testing session.""" diff --git a/metricflow/test/fixtures/sql_client_fixtures.py b/metricflow/test/fixtures/sql_client_fixtures.py index b54e019f4d..7968f5a86e 100644 --- a/metricflow/test/fixtures/sql_client_fixtures.py +++ b/metricflow/test/fixtures/sql_client_fixtures.py @@ -42,6 +42,9 @@ DBT_ENV_SECRET_PROJECT_ID = "DBT_ENV_SECRET_PROJECT_ID" DBT_ENV_SECRET_TOKEN_URI = "DBT_ENV_SECRET_TOKEN_URI" +# Trino is special, so it gets its own set of env vars. Keeping them split out here for consistency. +DBT_ENV_SECRET_CATALOG = "DBT_ENV_SECRET_CATALOG" + def __configure_test_env_from_url(url: str, password: str, schema: str) -> sqlalchemy.engine.URL: """Populates default env var mapping from a sqlalchemy URL string. @@ -120,6 +123,14 @@ def __configure_databricks_env_from_url(url: str, password: str, schema: str) -> os.environ[DBT_ENV_SECRET_HTTP_PATH] = http_path __configure_test_env_from_url(url_pieces[0], password=password, schema=schema) +def __configure_trino_env_from_url(url: str, password: str, schema: str) -> None: + """Databricks has a custom http path attribute, which we have encoded into a SqlAlchemy-like URL appendage. + + This custom parsing was ported from our original client implementation for backwards compatibility with the + existing CI job configurations. + """ + + pass def __initialize_dbt() -> None: """Invoke the dbt runner from the appropriate directory so we can fetch the relevant adapter. @@ -163,6 +174,10 @@ def make_test_sql_client(url: str, password: str, schema: str) -> SqlClientWithD __configure_databricks_env_from_url(url, password=password, schema=schema) __initialize_dbt() return AdapterBackedDDLSqlClient(adapter=get_adapter_by_type("databricks")) + elif dialect == SqlDialect.TRINO: + __configure_test_env_from_url(url, password=password, schema=schema) + __initialize_dbt() + return AdapterBackedDDLSqlClient(adapter=get_adapter_by_type("trino")) else: raise ValueError(f"Unknown dialect: `{dialect}` in URL {url}") diff --git a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py index 33e603bbc1..d9fa7cd2d1 100644 --- a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py +++ b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py @@ -93,6 +93,8 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str: if dtype == "string" or dtype == "object": if self.sql_engine_type is SqlEngine.DATABRICKS or self.sql_engine_type is SqlEngine.BIGQUERY: return "string" + if self.sql_engine_type is SqlEngine.TRINO: + return "varchar(100)" return "text" elif dtype == "boolean" or dtype == "bool": return "boolean" @@ -101,6 +103,8 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str: elif dtype == "float64": return self._sql_query_plan_renderer.expr_renderer.double_data_type elif dtype == "datetime64[ns]": + if self.sql_engine_type is SqlEngine.TRINO: # mptrino does implicitly cast datetime to timesta + return "varchar" return self._sql_query_plan_renderer.expr_renderer.timestamp_data_type else: raise ValueError(f"Encountered unexpected Pandas dtype ({dtype})!") diff --git a/metricflow/test/fixtures/sql_clients/common_client.py b/metricflow/test/fixtures/sql_clients/common_client.py index 4273d0d12e..ddda32aea8 100644 --- a/metricflow/test/fixtures/sql_clients/common_client.py +++ b/metricflow/test/fixtures/sql_clients/common_client.py @@ -14,6 +14,7 @@ class SqlDialect(ExtendedEnum): SNOWFLAKE = "snowflake" BIGQUERY = "bigquery" DATABRICKS = "databricks" + TRINO = "trino" T = TypeVar("T") diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql new file mode 100644 index 0000000000..dab2be52a2 --- /dev/null +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql @@ -0,0 +1,30 @@ +-- Read Elements From Semantic Model 'revenue' +SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user +FROM ***************************.fct_revenue revenue_src_10006 diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql new file mode 100644 index 0000000000..93f9b1f47a --- /dev/null +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql @@ -0,0 +1,57 @@ +-- Read Elements From Semantic Model 'id_verifications' +SELECT + 1 AS identity_verifications + , id_verifications_src_10003.ds AS ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds) AS ds__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy + , id_verifications_src_10003.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type + , id_verifications_src_10003.ds AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds) AS verification__ds__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy + , id_verifications_src_10003.ds_partitioned AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type AS verification__verification_type + , id_verifications_src_10003.verification_id AS verification + , id_verifications_src_10003.user_id AS user + , id_verifications_src_10003.user_id AS verification__user +FROM ***************************.fct_id_verifications id_verifications_src_10003 diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql new file mode 100644 index 0000000000..184fc0044a --- /dev/null +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql @@ -0,0 +1,30 @@ +-- Read Elements From Semantic Model 'users_latest' +SELECT + users_latest_src_10008.ds AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(week FROM users_latest_src_10008.ds) AS ds_latest__extract_week + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(dow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , users_latest_src_10008.ds AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(week FROM users_latest_src_10008.ds) AS user__ds_latest__extract_week + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(dow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user +FROM ***************************.dim_users_latest users_latest_src_10008 diff --git a/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql new file mode 100644 index 0000000000..801df5acef --- /dev/null +++ b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__day + , SUM(count_dogs) AS count_dogs +FROM ( + -- Read Elements From Semantic Model 'animals' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['count_dogs', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS count_dogs + FROM ***************************.fct_animals animals_src_0 +) subq_2 +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml new file mode 100644 index 0000000000..0d2369dcca --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml new file mode 100644 index 0000000000..99c2c23a43 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml new file mode 100644 index 0000000000..99b6619da9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml new file mode 100644 index 0000000000..53612723d0 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql new file mode 100644 index 0000000000..b954d8927e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql @@ -0,0 +1,467 @@ +-- Combine Metrics +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 +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_8.metric_time__day + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.booking_value + FROM ( + -- 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql new file mode 100644 index 0000000000..6ac18252b5 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Combine Metrics +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_value) AS booking_value +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_12 + GROUP BY + metric_time__day +) subq_14 +FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + ds AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds +) subq_19 +ON + subq_14.metric_time__day = subq_19.metric_time__day +GROUP BY + COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql new file mode 100644 index 0000000000..b1bf877e84 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql @@ -0,0 +1,202 @@ +-- Compute Metrics via Expressions +SELECT + subq_5.listing + , subq_5.listing__country_latest + , subq_5.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_4.listing + , subq_4.listing__country_latest + , SUM(subq_4.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 + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + GROUP BY + subq_4.listing + , subq_4.listing__country_latest +) subq_5 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql new file mode 100644 index 0000000000..7a53d1c84e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql @@ -0,0 +1,23 @@ +-- Join Standard Outputs +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + subq_7.listing AS listing + , listings_latest_src_10004.country AS listing__country_latest + , SUM(subq_7.bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'listing'] + SELECT + listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_7 +LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 +ON + subq_7.listing = listings_latest_src_10004.listing_id +GROUP BY + subq_7.listing + , listings_latest_src_10004.country diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql new file mode 100644 index 0000000000..5373f3b9a9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql @@ -0,0 +1,748 @@ +-- 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 +FROM ( + -- Combine Metrics + 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 + , subq_9.bookings AS bookings + , subq_19.views AS views + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.ds__day + , subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.ds__day + , subq_7.listing__country_latest + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__country_latest', 'ds__day'] + SELECT + subq_6.ds__day + , subq_6.listing__country_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + 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 + FROM ( + -- Pass Only Elements: + -- ['bookings', 'ds__day', 'listing'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + GROUP BY + subq_7.ds__day + , subq_7.listing__country_latest + ) subq_8 + ) subq_9 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_18.ds__day + , subq_18.listing__country_latest + , subq_18.views + FROM ( + -- Aggregate Measures + SELECT + subq_17.ds__day + , subq_17.listing__country_latest + , SUM(subq_17.views) AS views + FROM ( + -- Pass Only Elements: + -- ['views', 'listing__country_latest', 'ds__day'] + SELECT + subq_16.ds__day + , subq_16.listing__country_latest + , subq_16.views + FROM ( + -- Join Standard Outputs + 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 + FROM ( + -- Pass Only Elements: + -- ['views', 'ds__day', 'listing'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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 + , views_source_src_10009.ds AS ds__day + , DATE_TRUNC('week', views_source_src_10009.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_10009.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_10009.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_10009.ds) AS ds__year + , EXTRACT(year FROM views_source_src_10009.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_10009.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_10009.ds) AS ds__extract_month + , EXTRACT(week FROM views_source_src_10009.ds) AS ds__extract_week + , EXTRACT(day FROM views_source_src_10009.ds) AS ds__extract_day + , EXTRACT(dow FROM views_source_src_10009.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_10009.ds) AS ds__extract_doy + , views_source_src_10009.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_10009.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_doy + , views_source_src_10009.ds AS view__ds__day + , DATE_TRUNC('week', views_source_src_10009.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_10009.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_10009.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_10009.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_10009.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_10009.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_10009.ds) AS view__ds__extract_month + , EXTRACT(week FROM views_source_src_10009.ds) AS view__ds__extract_week + , EXTRACT(day FROM views_source_src_10009.ds) AS view__ds__extract_day + , EXTRACT(dow FROM views_source_src_10009.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_10009.ds) AS view__ds__extract_doy + , views_source_src_10009.ds_partitioned AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(week FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_week + , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(dow FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_10009.listing_id AS listing + , views_source_src_10009.user_id AS user + , views_source_src_10009.listing_id AS view__listing + , views_source_src_10009.user_id AS view__user + FROM ***************************.fct_views views_source_src_10009 + ) subq_10 + ) subq_11 + ) subq_12 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['country_latest', 'listing'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_13 + ) subq_14 + ) subq_15 + ON + subq_12.listing = subq_15.listing + ) subq_16 + ) subq_17 + GROUP BY + subq_17.ds__day + , subq_17.listing__country_latest + ) subq_18 + ) subq_19 + ON + ( + ( + subq_9.listing__country_latest = subq_19.listing__country_latest + ) OR ( + ( + subq_9.listing__country_latest IS NULL + ) AND ( + subq_19.listing__country_latest IS NULL + ) + ) + ) AND ( + ( + subq_9.ds__day = subq_19.ds__day + ) OR ( + (subq_9.ds__day IS NULL) AND (subq_19.ds__day IS NULL) + ) + ) +) subq_20 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql new file mode 100644 index 0000000000..02295e403e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql @@ -0,0 +1,82 @@ +-- Combine Metrics +-- Compute Metrics via Expressions +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 + , CAST(subq_30.bookings AS DOUBLE) / CAST(NULLIF(subq_40.views, 0) AS DOUBLE) AS bookings_per_view +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_10004.country AS listing__country_latest + , SUM(subq_23.bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'ds__day', 'listing'] + SELECT + ds AS ds__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_23 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_23.listing = listings_latest_src_10004.listing_id + GROUP BY + subq_23.ds__day + , listings_latest_src_10004.country +) subq_30 +INNER 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_10004.country AS listing__country_latest + , SUM(subq_33.views) AS views + FROM ( + -- Read Elements From Semantic Model 'views_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['views', 'ds__day', 'listing'] + SELECT + ds AS ds__day + , listing_id AS listing + , 1 AS views + FROM ***************************.fct_views views_source_src_10009 + ) subq_33 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_33.listing = listings_latest_src_10004.listing_id + GROUP BY + subq_33.ds__day + , listings_latest_src_10004.country +) subq_40 +ON + ( + ( + subq_30.listing__country_latest = subq_40.listing__country_latest + ) OR ( + ( + subq_30.listing__country_latest IS NULL + ) AND ( + subq_40.listing__country_latest IS NULL + ) + ) + ) AND ( + ( + subq_30.ds__day = subq_40.ds__day + ) OR ( + (subq_30.ds__day IS NULL) AND (subq_40.ds__day IS NULL) + ) + ) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql new file mode 100644 index 0000000000..1bd176c115 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql @@ -0,0 +1,205 @@ +-- 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 +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 + 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 + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + GROUP BY + subq_4.listing + , subq_4.listing__country_latest +) subq_5 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql new file mode 100644 index 0000000000..f22bdaf7cb --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql @@ -0,0 +1,31 @@ +-- Compute Metrics via Expressions +SELECT + listing + , listing__country_latest + , CAST(bookings AS DOUBLE) / CAST(NULLIF(bookers, 0) AS DOUBLE) AS bookings_per_booker +FROM ( + -- Join Standard Outputs + -- Aggregate Measures + SELECT + subq_7.listing AS listing + , listings_latest_src_10004.country AS listing__country_latest + , SUM(subq_7.bookings) AS bookings + , COUNT(DISTINCT subq_7.bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'bookers', 'listing'] + SELECT + listing_id AS listing + , 1 AS bookings + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_7 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_7.listing = listings_latest_src_10004.listing_id + GROUP BY + subq_7.listing + , listings_latest_src_10004.country +) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql new file mode 100644 index 0000000000..cd879426f7 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql @@ -0,0 +1,202 @@ +-- Compute Metrics via Expressions +SELECT + subq_5.listing + , subq_5.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 + 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 + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + GROUP BY + subq_4.listing + , subq_4.listing__country_latest +) subq_5 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql new file mode 100644 index 0000000000..caa4c0c6fe --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Compute Metrics via Expressions +SELECT + listing + , listing__country_latest + , booking_value * 0.05 AS booking_fees +FROM ( + -- Join Standard Outputs + -- Aggregate Measures + SELECT + bookings_source_src_10001.listing_id AS listing + , listings_latest_src_10004.country AS listing__country_latest + , SUM(bookings_source_src_10001.booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id + GROUP BY + bookings_source_src_10001.listing_id + , listings_latest_src_10004.country +) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql new file mode 100644 index 0000000000..5b6dd99cc4 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql @@ -0,0 +1,119 @@ +-- 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 +FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_1.ds__day + , subq_1.ds__day AS metric_time__day + , subq_1.bookings + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 +) subq_2 +WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql new file mode 100644 index 0000000000..bfc4959615 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql @@ -0,0 +1,11 @@ +-- Read Elements From Semantic Model '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] +SELECT + ds AS ds__day + , ds AS metric_time__day + , 1 AS bookings +FROM ***************************.fct_bookings bookings_source_src_10001 +WHERE ds BETWEEN '2020-01-01' AND '2020-01-02' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql new file mode 100644 index 0000000000..6920a36691 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql @@ -0,0 +1,94 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql new file mode 100644 index 0000000000..6596468bca --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS trailing_2_months_revenue +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql new file mode 100644 index 0000000000..4080ab9420 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql @@ -0,0 +1,94 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS revenue_mtd +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql new file mode 100644 index 0000000000..06853be07e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_mtd +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql new file mode 100644 index 0000000000..fcf74a5947 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql @@ -0,0 +1,89 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue'] + SELECT + subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql new file mode 100644 index 0000000000..ba2c45a4ca --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql @@ -0,0 +1,9 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(revenue) AS trailing_2_months_revenue +FROM ***************************.fct_revenue revenue_src_10006 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql new file mode 100644 index 0000000000..0143335613 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql @@ -0,0 +1,94 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS revenue_all_time +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql new file mode 100644 index 0000000000..220fb6083c --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_all_time +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..5cba3a3202 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -0,0 +1,138 @@ +-- Compute Metrics via Expressions +SELECT + subq_4.ds__month + , subq_4.txn_revenue AS revenue_all_time +FROM ( + -- Aggregate Measures + SELECT + subq_3.ds__month + , SUM(subq_3.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_2.ds__month + , subq_2.txn_revenue + FROM ( + -- 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_week + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.company__ds__day + , subq_1.company__ds__week + , subq_1.company__ds__month + , subq_1.company__ds__quarter + , subq_1.company__ds__year + , subq_1.company__ds__extract_year + , subq_1.company__ds__extract_quarter + , subq_1.company__ds__extract_month + , subq_1.company__ds__extract_week + , subq_1.company__ds__extract_day + , subq_1.company__ds__extract_dow + , subq_1.company__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_week + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , subq_1.user + , subq_1.company__user + , subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01' + ) subq_2 + ) subq_3 + GROUP BY + subq_3.ds__month +) subq_4 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..c420ef636f --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00] +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_all_time +FROM ***************************.fct_revenue revenue_src_10006 +WHERE created_at BETWEEN '2000-01-01' AND '2020-01-01' +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..414159089b --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql @@ -0,0 +1,138 @@ +-- Compute Metrics via Expressions +SELECT + subq_4.ds__month + , subq_4.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + subq_3.ds__month + , SUM(subq_3.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_2.ds__month + , subq_2.txn_revenue + FROM ( + -- Constrain Time Range to [2019-12-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_week + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.company__ds__day + , subq_1.company__ds__week + , subq_1.company__ds__month + , subq_1.company__ds__quarter + , subq_1.company__ds__year + , subq_1.company__ds__extract_year + , subq_1.company__ds__extract_quarter + , subq_1.company__ds__extract_month + , subq_1.company__ds__extract_week + , subq_1.company__ds__extract_day + , subq_1.company__ds__extract_dow + , subq_1.company__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_week + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , subq_1.user + , subq_1.company__user + , subq_1.txn_revenue + 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_week + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_week + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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_week AS metric_time__extract_week + , 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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2019-12-01' AND '2020-01-01' + ) subq_2 + ) subq_3 + GROUP BY + subq_3.ds__month +) subq_4 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..e3387b51e4 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Constrain Time Range to [2019-12-01T00:00:00, 2020-01-01T00:00:00] +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS trailing_2_months_revenue +FROM ***************************.fct_revenue revenue_src_10006 +WHERE created_at BETWEEN '2019-12-01' AND '2020-01-01' +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql new file mode 100644 index 0000000000..5b4011175d --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql @@ -0,0 +1,479 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , subq_4.ref_bookings AS ref_bookings + , subq_9.bookings AS bookings + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.referred_bookings AS ref_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.referred_bookings) AS referred_bookings + FROM ( + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.referred_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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + ON + ( + subq_4.metric_time__day = subq_9.metric_time__day + ) OR ( + ( + subq_4.metric_time__day IS NULL + ) AND ( + subq_9.metric_time__day IS NULL + ) + ) +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql new file mode 100644 index 0000000000..336e7623a6 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql @@ -0,0 +1,59 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) AS metric_time__day + , subq_15.ref_bookings AS ref_bookings + , subq_20.bookings AS bookings + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(referred_bookings) AS ref_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + GROUP BY + metric_time__day + ) subq_15 + INNER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + GROUP BY + metric_time__day + ) subq_20 + ON + ( + subq_15.metric_time__day = subq_20.metric_time__day + ) OR ( + ( + subq_15.metric_time__day IS NULL + ) AND ( + subq_20.metric_time__day IS NULL + ) + ) +) subq_21 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql new file mode 100644 index 0000000000..d11a69936d --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , subq_4.bookings AS bookings + , subq_12.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 + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + INNER 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 + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + ) subq_11 + ) subq_12 + ON + ( + subq_4.metric_time__day = subq_12.metric_time__day + ) OR ( + ( + subq_4.metric_time__day IS NULL + ) AND ( + subq_12.metric_time__day IS NULL + ) + ) +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql new file mode 100644 index 0000000000..425f3c5f99 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , subq_18.bookings AS bookings + , subq_26.bookings_at_start_of_month AS bookings_at_start_of_month + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__day + ) subq_18 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + GROUP BY + subq_22.ds + ) subq_26 + ON + ( + subq_18.metric_time__day = subq_26.metric_time__day + ) OR ( + ( + subq_18.metric_time__day IS NULL + ) AND ( + subq_26.metric_time__day IS NULL + ) + ) +) subq_27 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql new file mode 100644 index 0000000000..b98d6d0f3d --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -0,0 +1,586 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__week + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week + , subq_4.bookings AS bookings + , subq_12.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 + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__week + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__week'] + SELECT + subq_1.metric_time__week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__week + ) subq_3 + ) subq_4 + INNER 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 + DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + GROUP BY + subq_10.metric_time__week + ) subq_11 + ) subq_12 + ON + ( + subq_4.metric_time__week = subq_12.metric_time__week + ) OR ( + ( + subq_4.metric_time__week IS NULL + ) AND ( + subq_12.metric_time__week IS NULL + ) + ) +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..b458c826f3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__week + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week + , subq_18.bookings AS bookings + , subq_26.bookings_at_start_of_month AS bookings_at_start_of_month + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__week + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__week'] + SELECT + DATE_TRUNC('week', ds) AS metric_time__week + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__week + ) subq_18 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + GROUP BY + DATE_TRUNC('week', subq_22.ds) + ) subq_26 + ON + ( + subq_18.metric_time__week = subq_26.metric_time__week + ) OR ( + ( + subq_18.metric_time__week IS NULL + ) AND ( + subq_26.metric_time__week IS NULL + ) + ) +) subq_27 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql new file mode 100644 index 0000000000..38aeec72e9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , subq_4.bookings AS bookings + , subq_12.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + INNER 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 + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + ) subq_11 + ) subq_12 + ON + ( + subq_4.metric_time__day = subq_12.metric_time__day + ) OR ( + ( + subq_4.metric_time__day IS NULL + ) AND ( + subq_12.metric_time__day IS NULL + ) + ) +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql new file mode 100644 index 0000000000..28b07ca0e2 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , subq_18.bookings AS bookings + , subq_26.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__day + ) subq_18 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + GROUP BY + subq_22.ds + ) subq_26 + ON + ( + subq_18.metric_time__day = subq_26.metric_time__day + ) OR ( + ( + subq_18.metric_time__day IS NULL + ) AND ( + subq_26.metric_time__day IS NULL + ) + ) +) subq_27 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql new file mode 100644 index 0000000000..0ad6211336 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__quarter + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) AS metric_time__quarter + , subq_4.bookings AS bookings + , subq_12.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__quarter + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__quarter + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__quarter'] + SELECT + subq_1.metric_time__quarter + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__quarter + ) subq_3 + ) subq_4 + INNER 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 + DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__quarter + ) subq_11 + ) subq_12 + ON + ( + subq_4.metric_time__quarter = subq_12.metric_time__quarter + ) OR ( + ( + subq_4.metric_time__quarter IS NULL + ) AND ( + subq_12.metric_time__quarter IS NULL + ) + ) +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..db9eaf374e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__quarter + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) AS metric_time__quarter + , subq_18.bookings AS bookings + , subq_26.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__quarter + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__quarter'] + SELECT + DATE_TRUNC('quarter', ds) AS metric_time__quarter + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__quarter + ) subq_18 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + GROUP BY + DATE_TRUNC('quarter', subq_22.ds) + ) subq_26 + ON + ( + subq_18.metric_time__quarter = subq_26.metric_time__quarter + ) OR ( + ( + subq_18.metric_time__quarter IS NULL + ) AND ( + subq_26.metric_time__quarter IS NULL + ) + ) +) subq_27 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql new file mode 100644 index 0000000000..c987150223 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -0,0 +1,691 @@ +-- Compute Metrics via Expressions +SELECT + subq_16.metric_time__day + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day + , subq_7.month_start_bookings AS month_start_bookings + , subq_15.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ) subq_7 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_14.metric_time__day + , subq_14.bookings AS bookings_1_month_ago + FROM ( + -- Aggregate Measures + SELECT + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_12.metric_time__day + , subq_12.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_10.metric_time__day AS metric_time__day + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 + FROM ( + -- Date Spine + SELECT + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_8 + ) subq_9 + ON + subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day + ) subq_12 + ) subq_13 + GROUP BY + subq_13.metric_time__day + ) subq_14 + ) subq_15 + ON + ( + subq_7.metric_time__day = subq_15.metric_time__day + ) OR ( + ( + subq_7.metric_time__day IS NULL + ) AND ( + subq_15.metric_time__day IS NULL + ) + ) +) subq_16 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql new file mode 100644 index 0000000000..e239a53fef --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -0,0 +1,67 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , subq_24.month_start_bookings AS month_start_bookings + , subq_32.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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + ON + DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + GROUP BY + subq_20.ds + ) subq_24 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_26 + ON + subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + GROUP BY + subq_28.ds + ) subq_32 + ON + ( + subq_24.metric_time__day = subq_32.metric_time__day + ) OR ( + ( + subq_24.metric_time__day IS NULL + ) AND ( + subq_32.metric_time__day IS NULL + ) + ) +) subq_33 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql new file mode 100644 index 0000000000..cddee48ddb --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -0,0 +1,692 @@ +-- Compute Metrics via Expressions +SELECT + subq_16.metric_time__year + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) AS metric_time__year + , subq_7.month_start_bookings AS month_start_bookings + , subq_15.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__year'] + SELECT + subq_4.metric_time__year + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + DATE_TRUNC('year', subq_2.metric_time__day) 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + GROUP BY + subq_5.metric_time__year + ) subq_6 + ) subq_7 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_14.metric_time__year + , subq_14.bookings AS bookings_1_month_ago + FROM ( + -- Aggregate Measures + SELECT + subq_13.metric_time__year + , SUM(subq_13.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__year'] + SELECT + subq_12.metric_time__year + , subq_12.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 + FROM ( + -- Date Spine + SELECT + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_8 + ) subq_9 + ON + subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day + ) subq_12 + ) subq_13 + GROUP BY + subq_13.metric_time__year + ) subq_14 + ) subq_15 + ON + ( + subq_7.metric_time__year = subq_15.metric_time__year + ) OR ( + ( + subq_7.metric_time__year IS NULL + ) AND ( + subq_15.metric_time__year IS NULL + ) + ) +) subq_16 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..f4b9c2a35c --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -0,0 +1,68 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__year + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) AS metric_time__year + , subq_24.month_start_bookings AS month_start_bookings + , subq_32.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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + ON + DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + GROUP BY + DATE_TRUNC('year', subq_20.ds) + ) subq_24 + INNER 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_26 + ON + subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + GROUP BY + DATE_TRUNC('year', subq_28.ds) + ) subq_32 + ON + ( + subq_24.metric_time__year = subq_32.metric_time__year + ) OR ( + ( + subq_24.metric_time__year IS NULL + ) AND ( + subq_32.metric_time__year IS NULL + ) + ) +) subq_33 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql new file mode 100644 index 0000000000..94cf44278b --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -0,0 +1,460 @@ +-- Compute Metrics via Expressions +SELECT + 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_9.metric_time__day + , subq_9.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 + FROM ( + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_7.metric_time__day + , subq_7.bookers + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_5.metric_time__day AS metric_time__day + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 + FROM ( + -- Date Spine + SELECT + 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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_week AS metric_time__extract_week + , subq_1.metric_time__extract_day AS metric_time__extract_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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + ON + subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_7 + ) subq_8 + GROUP BY + subq_8.metric_time__day + ) subq_9 +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql new file mode 100644 index 0000000000..1b96977064 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -0,0 +1,34 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Join Self Over Time Range + SELECT + subq_14.ds AS metric_time__day + , bookings_source_src_10001.guest_id AS bookers + FROM ***************************.mf_time_spine subq_14 + INNER JOIN + ***************************.fct_bookings bookings_source_src_10001 + ON + ( + bookings_source_src_10001.ds <= subq_14.ds + ) AND ( + bookings_source_src_10001.ds > subq_14.ds - INTERVAL 2 day + ) + ) subq_15 + ON + subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + GROUP BY + subq_17.ds +) subq_21 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql new file mode 100644 index 0000000000..6b4f9e31f9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql new file mode 100644 index 0000000000..b5a8855b9c --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -0,0 +1,27 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings_5_days_ago AS bookings_5_day_lag +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + ON + subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + GROUP BY + subq_11.ds +) subq_15 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql new file mode 100644 index 0000000000..40f6785af3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql @@ -0,0 +1,404 @@ +-- Order By ['listing__country_latest'] Limit 100 +SELECT + subq_10.listing__country_latest +FROM ( + -- Pass Only Elements: + -- ['listing__country_latest'] + SELECT + subq_9.listing__country_latest + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.listing__country_latest + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__country_latest'] + SELECT + subq_6.listing__country_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_5.country_latest AS listing__country_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing'] + SELECT + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + GROUP BY + subq_7.listing__country_latest + ) subq_8 + ) subq_9 +) subq_10 +ORDER BY subq_10.listing__country_latest +LIMIT 100 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql new file mode 100644 index 0000000000..328d6a2d79 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql @@ -0,0 +1,19 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +-- Pass Only Elements: +-- ['listing__country_latest'] +-- Order By ['listing__country_latest'] Limit 100 +SELECT + listings_latest_src_10004.country AS listing__country_latest +FROM ***************************.fct_bookings bookings_source_src_10001 +LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 +ON + bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id +GROUP BY + listings_latest_src_10004.country +ORDER BY listing__country_latest +LIMIT 100 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql new file mode 100644 index 0000000000..a43457fcbd --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql @@ -0,0 +1,103 @@ +-- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_0 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql new file mode 100644 index 0000000000..24beb367f1 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql @@ -0,0 +1,6 @@ +-- Read Elements From Semantic Model 'bookings_source' +-- Pass Only Elements: +-- ['bookings'] +SELECT + 1 AS bookings +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql new file mode 100644 index 0000000000..a3ce23fb89 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql @@ -0,0 +1,111 @@ +-- Constrain Output with WHERE +SELECT + subq_1.ds__day + , subq_1.bookings +FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 +) subq_1 +WHERE booking__ds__day = '2020-01-01' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql new file mode 100644 index 0000000000..c850362ca3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Constrain Output with WHERE +SELECT + ds__day + , bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'ds__day'] + SELECT + ds AS ds__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_3 +WHERE booking__ds__day = '2020-01-01' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql new file mode 100644 index 0000000000..70919d8caa --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql @@ -0,0 +1,409 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant'] + SELECT + subq_8.is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.is_instant + , subq_7.listing__country_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing__country_latest'] + SELECT + subq_6.is_instant + , subq_6.listing__country_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.is_instant AS is_instant + , subq_5.country_latest AS listing__country_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_9.is_instant +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql new file mode 100644 index 0000000000..29bb79a181 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql @@ -0,0 +1,35 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['bookings', 'is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing__country_latest'] + SELECT + subq_13.is_instant AS is_instant + , listings_latest_src_10004.country AS listing__country_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_13.listing = listings_latest_src_10004.listing_id +) subq_18 +WHERE listing__country_latest = 'us' +GROUP BY + is_instant diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql new file mode 100644 index 0000000000..6e4488a729 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql @@ -0,0 +1,334 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__day + , subq_9.bookings AS family_bookings +FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_7.metric_time__day + , subq_7.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.metric_time__day + , subq_6.listing__capacity + , subq_6.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__capacity', 'metric_time__day'] + SELECT + subq_5.metric_time__day + , subq_5.listing__capacity + , subq_5.bookings + FROM ( + -- Join Standard Outputs + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , bookings_source_src_10015.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , bookings_source_src_10015.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) 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_10017.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month + , EXTRACT(week FROM listings_src_10017.active_from) AS window_start__extract_week + , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day + , EXTRACT(dow FROM listings_src_10017.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy + , listings_src_10017.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month + , EXTRACT(week FROM listings_src_10017.active_to) AS window_end__extract_week + , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day + , EXTRACT(dow FROM listings_src_10017.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy + , listings_src_10017.country + , listings_src_10017.is_lux + , listings_src_10017.capacity + , listings_src_10017.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month + , EXTRACT(week FROM listings_src_10017.active_from) AS listing__window_start__extract_week + , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day + , EXTRACT(dow FROM listings_src_10017.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy + , listings_src_10017.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month + , EXTRACT(week FROM listings_src_10017.active_to) AS listing__window_end__extract_week + , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day + , EXTRACT(dow FROM listings_src_10017.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy + , listings_src_10017.country AS listing__country + , listings_src_10017.is_lux AS listing__is_lux + , listings_src_10017.capacity AS listing__capacity + , listings_src_10017.listing_id AS listing + , listings_src_10017.user_id AS user + , listings_src_10017.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10017 + ) subq_3 + ) subq_4 + ON + ( + 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_5 + ) subq_6 + WHERE listing__capacity > 2 + ) subq_7 + ) subq_8 + GROUP BY + subq_8.metric_time__day +) subq_9 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..86a2010b35 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql @@ -0,0 +1,47 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['bookings', 'metric_time__day'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__day + , SUM(bookings) AS family_bookings +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_10017.capacity AS listing__capacity + , subq_12.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + ds AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_12 + LEFT OUTER JOIN + ***************************.dim_listings listings_src_10017 + ON + ( + subq_12.listing = listings_src_10017.listing_id + ) AND ( + ( + subq_12.metric_time__day >= listings_src_10017.active_from + ) AND ( + ( + subq_12.metric_time__day < listings_src_10017.active_to + ) OR ( + listings_src_10017.active_to IS NULL + ) + ) + ) +) subq_16 +WHERE listing__capacity > 2 +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql new file mode 100644 index 0000000000..9f23719b49 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql @@ -0,0 +1,247 @@ +-- 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 +FROM ( + -- Date 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 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.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 + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + SELECT + subq_1.metric_time__day + , subq_1.listing + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.listing + ) subq_3 +) subq_4 +ON + DATE_TRUNC('month', subq_5.metric_time__day) = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql new file mode 100644 index 0000000000..6a4ced8cd8 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- 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 +FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_12 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , listing + , booking_value * 0.05 AS booking_fees + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + -- Aggregate Measures + SELECT + ds AS metric_time__day + , listing_id AS listing + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds + , listing_id + ) subq_10 +) subq_11 +ON + DATE_TRUNC('month', subq_12.metric_time__day) = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql new file mode 100644 index 0000000000..406b83cae3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -0,0 +1,247 @@ +-- 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 +FROM ( + -- Date 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 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.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 + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + SELECT + subq_1.metric_time__day + , subq_1.listing + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.listing + ) subq_3 +) subq_4 +ON + subq_5.metric_time__day - INTERVAL 10 day = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql new file mode 100644 index 0000000000..4a9399b1f2 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- 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 +FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_12 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , listing + , booking_value * 0.05 AS booking_fees + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + -- Aggregate Measures + SELECT + ds AS metric_time__day + , listing_id AS listing + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds + , listing_id + ) subq_10 +) subq_11 +ON + subq_12.metric_time__day - INTERVAL 10 day = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql new file mode 100644 index 0000000000..2093e49b0b --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql @@ -0,0 +1,247 @@ +-- 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 +FROM ( + -- Date 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 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.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 + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + SELECT + subq_1.metric_time__day + , subq_1.listing + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.listing + ) subq_3 +) subq_4 +ON + subq_5.metric_time__day = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql new file mode 100644 index 0000000000..4afadfc929 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- 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 +FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_12 +INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , listing + , booking_value * 0.05 AS booking_fees + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day', 'listing'] + -- Aggregate Measures + SELECT + ds AS metric_time__day + , listing_id AS listing + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds + , listing_id + ) subq_10 +) subq_11 +ON + subq_12.metric_time__day = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql new file mode 100644 index 0000000000..eb506ddf59 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql @@ -0,0 +1,234 @@ +-- Order By [] Limit 1 +SELECT + subq_4.ds__day + , subq_4.bookings +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.ds__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'ds__day'] + SELECT + subq_1.ds__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__day + ) subq_3 +) subq_4 +LIMIT 1 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql new file mode 100644 index 0000000000..6db56759fc --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql @@ -0,0 +1,19 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +-- Order By [] Limit 1 +SELECT + ds__day + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'ds__day'] + SELECT + ds AS ds__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_7 +GROUP BY + ds__day +LIMIT 1 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql new file mode 100644 index 0000000000..d5688f0e2d --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql @@ -0,0 +1,160 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.listing__country_latest + , subq_3.listings +FROM ( + -- Aggregate Measures + SELECT + subq_2.listing__country_latest + , SUM(subq_2.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings', 'listing__country_latest'] + SELECT + subq_1.listing__country_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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.listing__country_latest +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql new file mode 100644 index 0000000000..f7932552c3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(listings) AS listings +FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['listings', 'listing__country_latest'] + SELECT + country AS listing__country_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_6 +GROUP BY + listing__country_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql new file mode 100644 index 0000000000..dbfcb34b94 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql @@ -0,0 +1,114 @@ +-- 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 +FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 +) subq_1 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql new file mode 100644 index 0000000000..2118e57c95 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql @@ -0,0 +1,10 @@ +-- Read Elements From Semantic Model 'bookings_source' +-- Pass Only Elements: +-- ['bookings', 'instant_bookings', 'average_booking_value', 'bookers'] +-- Aggregate Measures +SELECT + SUM(1) AS bookings + , SUM(CASE WHEN is_instant THEN 1 ELSE 0 END) AS instant_bookings + , COUNT(DISTINCT guest_id) AS bookers + , AVG(booking_value) AS average_booking_value +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql new file mode 100644 index 0000000000..e5349b0d17 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql @@ -0,0 +1,1083 @@ +-- Compute Metrics via Expressions +SELECT + subq_29.metric_time__day + , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , subq_11.average_booking_value AS average_booking_value + , subq_23.bookings AS bookings + , subq_28.booking_value AS booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , AVG(subq_9.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: + -- ['average_booking_value', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.average_booking_value + FROM ( + -- Pass Only Elements: + -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.listing__is_lux_latest + , subq_6.average_booking_value + FROM ( + -- Join Standard Outputs + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_9.metric_time__day + ) subq_10 + ) subq_11 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_22.metric_time__day + , subq_22.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_21.metric_time__day + , SUM(subq_21.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_20.metric_time__day + , subq_20.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_19.metric_time__day + , subq_19.listing__is_lux_latest + , subq_19.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_18.metric_time__day + , subq_18.listing__is_lux_latest + , subq_18.bookings + FROM ( + -- Join Standard Outputs + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_21.metric_time__day + ) subq_22 + ) subq_23 + ON + ( + subq_11.metric_time__day = subq_23.metric_time__day + ) OR ( + ( + subq_11.metric_time__day IS NULL + ) AND ( + subq_23.metric_time__day IS NULL + ) + ) + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_27.metric_time__day + , subq_27.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_26.metric_time__day + , SUM(subq_26.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + SELECT + subq_25.metric_time__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_24 + ) subq_25 + ) subq_26 + GROUP BY + subq_26.metric_time__day + ) subq_27 + ) subq_28 + ON + ( + subq_11.metric_time__day = subq_28.metric_time__day + ) OR ( + ( + subq_11.metric_time__day IS NULL + ) AND ( + subq_28.metric_time__day IS NULL + ) + ) +) subq_29 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..eb22b75d5e --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql @@ -0,0 +1,110 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day) AS metric_time__day + , subq_41.average_booking_value AS average_booking_value + , subq_53.bookings AS bookings + , subq_58.booking_value AS booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + bookings_source_src_10001.ds AS metric_time__day + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , bookings_source_src_10001.booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id + ) subq_37 + WHERE listing__is_lux_latest + GROUP BY + metric_time__day + ) subq_41 + INNER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['bookings', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_44.metric_time__day AS metric_time__day + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , subq_44.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + ds AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_44 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_44.listing = listings_latest_src_10004.listing_id + ) subq_49 + WHERE listing__is_lux_latest + GROUP BY + metric_time__day + ) subq_53 + ON + ( + subq_41.metric_time__day = subq_53.metric_time__day + ) OR ( + ( + subq_41.metric_time__day IS NULL + ) AND ( + subq_53.metric_time__day IS NULL + ) + ) + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + ds AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds + ) subq_58 + ON + ( + subq_41.metric_time__day = subq_58.metric_time__day + ) OR ( + ( + subq_41.metric_time__day IS NULL + ) AND ( + subq_58.metric_time__day IS NULL + ) + ) +) subq_59 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql new file mode 100644 index 0000000000..c11754db0d --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql @@ -0,0 +1,495 @@ +-- 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 +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day + , subq_6.booking_value_with_is_instant_constraint AS booking_value_with_is_instant_constraint + , subq_11.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 + FROM ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.booking_value) AS booking_value + FROM ( + -- 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + INNER 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 + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_7 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + ) subq_10 + ) subq_11 + ON + ( + subq_6.metric_time__day = subq_11.metric_time__day + ) OR ( + ( + subq_6.metric_time__day IS NULL + ) AND ( + subq_11.metric_time__day IS NULL + ) + ) +) subq_12 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql new file mode 100644 index 0000000000..7c202ae455 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -0,0 +1,53 @@ +-- Combine Metrics +-- Compute Metrics via Expressions +SELECT + COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_24.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(booking_value) AS booking_value_with_is_instant_constraint + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + ds AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_15 + WHERE booking__is_instant + GROUP BY + metric_time__day +) subq_19 +INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + ds AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + ds +) subq_24 +ON + ( + subq_19.metric_time__day = subq_24.metric_time__day + ) OR ( + ( + subq_19.metric_time__day IS NULL + ) AND ( + subq_24.metric_time__day IS NULL + ) + ) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql new file mode 100644 index 0000000000..bd41d48bd9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -0,0 +1,249 @@ +-- Compute Metrics via Expressions +SELECT + subq_6.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 + FROM ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.booking__is_instant + , subq_2.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE NOT booking__is_instant + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 +) subq_6 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql new file mode 100644 index 0000000000..c012c97a59 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -0,0 +1,28 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , delayed_bookings * 2 AS double_counted_delayed_bookings +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS delayed_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + SELECT + ds AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + WHERE NOT booking__is_instant + GROUP BY + metric_time__day +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql new file mode 100644 index 0000000000..ecc15101fe --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -0,0 +1,390 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.listings, 0) AS DOUBLE) AS bookings_per_listing +FROM ( + -- Combine Metrics + SELECT + subq_4.bookings AS bookings + , subq_9.listings AS listings + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings'] + SELECT + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + ) subq_3 + ) subq_4 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_8.listings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_7.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings'] + SELECT + subq_6.listings + FROM ( + -- 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_5 + ) subq_6 + ) subq_7 + ) subq_8 + ) subq_9 +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql new file mode 100644 index 0000000000..9be945ab42 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Combine Metrics +-- Compute Metrics via Expressions +SELECT + CAST(subq_15.bookings AS DOUBLE) / CAST(NULLIF(subq_20.listings, 0) AS DOUBLE) AS bookings_per_listing +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_15 +CROSS JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['listings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_20 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql new file mode 100644 index 0000000000..79946c1bc1 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql @@ -0,0 +1,488 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.listing__user__home_state_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , subq_9.listing__user__home_state_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- 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 + FROM ( + -- Join Standard Outputs + 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.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'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , bookings_source_src_10015.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , bookings_source_src_10015.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + 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_week AS window_start__extract_week + , 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_week AS window_end__extract_week + , 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_week AS listing__window_start__extract_week + , 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_week AS listing__window_end__extract_week + , 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_week AS user__ds__extract_week + , 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_10017.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month + , EXTRACT(week FROM listings_src_10017.active_from) AS window_start__extract_week + , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day + , EXTRACT(dow FROM listings_src_10017.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy + , listings_src_10017.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month + , EXTRACT(week FROM listings_src_10017.active_to) AS window_end__extract_week + , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day + , EXTRACT(dow FROM listings_src_10017.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy + , listings_src_10017.country + , listings_src_10017.is_lux + , listings_src_10017.capacity + , listings_src_10017.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month + , EXTRACT(week FROM listings_src_10017.active_from) AS listing__window_start__extract_week + , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day + , EXTRACT(dow FROM listings_src_10017.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy + , listings_src_10017.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month + , EXTRACT(week FROM listings_src_10017.active_to) AS listing__window_end__extract_week + , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day + , EXTRACT(dow FROM listings_src_10017.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy + , listings_src_10017.country AS listing__country + , listings_src_10017.is_lux AS listing__is_lux + , listings_src_10017.capacity AS listing__capacity + , listings_src_10017.listing_id AS listing + , listings_src_10017.user_id AS user + , listings_src_10017.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10017 + ) 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_week', + -- '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_week', + -- '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_week + , 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_week + , 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 + users_latest_src_10021.ds AS ds__day + , DATE_TRUNC('week', users_latest_src_10021.ds) AS ds__week + , DATE_TRUNC('month', users_latest_src_10021.ds) AS ds__month + , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS ds__quarter + , DATE_TRUNC('year', users_latest_src_10021.ds) AS ds__year + , EXTRACT(year FROM users_latest_src_10021.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10021.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10021.ds) AS ds__extract_month + , EXTRACT(week FROM users_latest_src_10021.ds) AS ds__extract_week + , EXTRACT(day FROM users_latest_src_10021.ds) AS ds__extract_day + , EXTRACT(dow FROM users_latest_src_10021.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10021.ds) AS ds__extract_doy + , users_latest_src_10021.home_state_latest + , users_latest_src_10021.ds AS user__ds__day + , DATE_TRUNC('week', users_latest_src_10021.ds) AS user__ds__week + , DATE_TRUNC('month', users_latest_src_10021.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_latest_src_10021.ds) AS user__ds__year + , EXTRACT(year FROM users_latest_src_10021.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10021.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10021.ds) AS user__ds__extract_month + , EXTRACT(week FROM users_latest_src_10021.ds) AS user__ds__extract_week + , EXTRACT(day FROM users_latest_src_10021.ds) AS user__ds__extract_day + , EXTRACT(dow FROM users_latest_src_10021.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10021.ds) AS user__ds__extract_doy + , users_latest_src_10021.home_state_latest AS user__home_state_latest + , users_latest_src_10021.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10021 + ) subq_4 + ) subq_5 + ON + subq_3.user = subq_5.user + ) subq_6 + ) subq_7 + ON + ( + subq_2.listing = subq_7.listing + ) 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_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + , subq_9.listing__user__home_state_latest +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..feb5ed0fdc --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql @@ -0,0 +1,52 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['bookings', 'listing__user__home_state_latest', 'metric_time__day'] +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + ds AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 +) subq_13 +LEFT OUTER JOIN ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + SELECT + listings_src_10017.active_from AS window_start__day + , listings_src_10017.active_to AS window_end__day + , listings_src_10017.listing_id AS listing + , users_latest_src_10021.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings listings_src_10017 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_10021 + ON + listings_src_10017.user_id = users_latest_src_10021.user_id +) subq_18 +ON + ( + subq_13.listing = subq_18.listing + ) AND ( + ( + subq_13.metric_time__day >= subq_18.window_start__day + ) AND ( + ( + subq_13.metric_time__day < subq_18.window_end__day + ) OR ( + subq_18.window_end__day IS NULL + ) + ) + ) +GROUP BY + subq_13.metric_time__day + , subq_18.user__home_state_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql new file mode 100644 index 0000000000..1cfb7780a7 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql @@ -0,0 +1,467 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.listing__lux_listing__is_confirmed_lux + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , subq_9.listing__lux_listing__is_confirmed_lux + , SUM(subq_9.bookings) AS bookings + FROM ( + -- 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 + FROM ( + -- Join Standard Outputs + 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 + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , bookings_source_src_10015.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , bookings_source_src_10015.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , bookings_source_src_10015.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10015.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['lux_listing__is_confirmed_lux', + -- 'lux_listing__window_start__day', + -- 'lux_listing__window_end__day', + -- '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_week AS lux_listing__window_start__extract_week + , 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_week AS lux_listing__window_end__extract_week + , 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_10018.listing_id AS listing + , lux_listing_mapping_src_10018.lux_listing_id AS lux_listing + , lux_listing_mapping_src_10018.lux_listing_id AS listing__lux_listing + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + ) 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_week', + -- '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_week', + -- '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_week', + -- '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_week', + -- '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_week + , 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_week + , 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_week + , 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_week + , 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_10019.valid_from AS window_start__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS window_start__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS window_start__year + , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS window_start__extract_month + , EXTRACT(week FROM lux_listings_src_10019.valid_from) AS window_start__extract_week + , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS window_start__extract_day + , EXTRACT(dow FROM lux_listings_src_10019.valid_from) AS window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS window_start__extract_doy + , lux_listings_src_10019.valid_to AS window_end__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS window_end__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS window_end__year + , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS window_end__extract_month + , EXTRACT(week FROM lux_listings_src_10019.valid_to) AS window_end__extract_week + , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS window_end__extract_day + , EXTRACT(dow FROM lux_listings_src_10019.valid_to) AS window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS window_end__extract_doy + , lux_listings_src_10019.is_confirmed_lux + , lux_listings_src_10019.valid_from AS lux_listing__window_start__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS lux_listing__window_start__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS lux_listing__window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS lux_listing__window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS lux_listing__window_start__year + , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_month + , EXTRACT(week FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_week + , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_day + , EXTRACT(dow FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_doy + , lux_listings_src_10019.valid_to AS lux_listing__window_end__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS lux_listing__window_end__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS lux_listing__window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS lux_listing__window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS lux_listing__window_end__year + , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_month + , EXTRACT(week FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_week + , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_day + , EXTRACT(dow FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_doy + , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux + , lux_listings_src_10019.lux_listing_id AS lux_listing + FROM ***************************.dim_lux_listings lux_listings_src_10019 + ) subq_4 + ) subq_5 + ON + subq_3.lux_listing = subq_5.lux_listing + ) subq_6 + ) subq_7 + ON + ( + subq_2.listing = subq_7.listing + ) 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_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + , subq_9.listing__lux_listing__is_confirmed_lux +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..f1b419a284 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql @@ -0,0 +1,55 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['bookings', 'listing__lux_listing__is_confirmed_lux', 'metric_time__day'] +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + ds AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 +) subq_13 +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_10019.valid_from AS lux_listing__window_start__day + , lux_listings_src_10019.valid_to AS lux_listing__window_end__day + , lux_listing_mapping_src_10018.listing_id AS listing + , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + LEFT OUTER JOIN + ***************************.dim_lux_listings lux_listings_src_10019 + ON + lux_listing_mapping_src_10018.lux_listing_id = lux_listings_src_10019.lux_listing_id +) subq_18 +ON + ( + subq_13.listing = subq_18.listing + ) AND ( + ( + subq_13.metric_time__day >= subq_18.lux_listing__window_start__day + ) AND ( + ( + subq_13.metric_time__day < subq_18.lux_listing__window_end__day + ) OR ( + subq_18.lux_listing__window_end__day IS NULL + ) + ) + ) +GROUP BY + subq_13.metric_time__day + , subq_18.lux_listing__is_confirmed_lux diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql new file mode 100644 index 0000000000..7e38380b20 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql @@ -0,0 +1,260 @@ +-- 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 +FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 +) subq_1 +LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_2 +) subq_3 +ON + subq_1.listing = subq_3.listing +LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_4 +) subq_5 +ON + subq_1.listing = subq_5.listing diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql new file mode 100644 index 0000000000..8180d208b3 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql @@ -0,0 +1,37 @@ +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'listing'] + SELECT + listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_7 +LEFT OUTER JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Pass Only Elements: + -- ['country_latest', 'listing'] + SELECT + listing_id AS listing + , country AS country_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_9 +ON + subq_7.listing = subq_9.listing +LEFT OUTER JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Pass Only Elements: + -- ['country_latest', 'listing'] + SELECT + listing_id AS listing + , country AS country_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_11 +ON + subq_7.listing = subq_11.listing diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql new file mode 100644 index 0000000000..c742d95f11 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql @@ -0,0 +1,388 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.account_id__customer_id__customer_name + , subq_10.txn_count +FROM ( + -- Aggregate Measures + SELECT + subq_9.account_id__customer_id__customer_name + , SUM(subq_9.txn_count) AS txn_count + FROM ( + -- Pass Only Elements: + -- ['txn_count', 'account_id__customer_id__customer_name'] + SELECT + subq_8.account_id__customer_id__customer_name + , subq_8.txn_count + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds_partitioned__day AS ds_partitioned__day + , subq_7.ds_partitioned__day AS account_id__ds_partitioned__day + , subq_2.account_id AS account_id + , subq_7.customer_id__customer_name AS account_id__customer_id__customer_name + , subq_2.txn_count AS txn_count + FROM ( + -- Pass Only Elements: + -- ['txn_count', 'ds_partitioned__day', 'account_id'] + SELECT + subq_1.ds_partitioned__day + , subq_1.account_id + , subq_1.txn_count + FROM ( + -- Metric Time Dimension 'ds' + 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10010.txn_count + , account_month_txns_src_10010.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_doy + , account_month_txns_src_10010.ds AS ds__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS ds__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS ds__year + , EXTRACT(year FROM account_month_txns_src_10010.ds) AS ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds) AS ds__extract_month + , EXTRACT(week FROM account_month_txns_src_10010.ds) AS ds__extract_week + , EXTRACT(day FROM account_month_txns_src_10010.ds) AS ds__extract_day + , EXTRACT(dow FROM account_month_txns_src_10010.ds) AS ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS ds__extract_doy + , account_month_txns_src_10010.account_month + , account_month_txns_src_10010.ds_partitioned AS account_id__ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(week FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_week + , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(dow FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , account_month_txns_src_10010.ds AS account_id__ds__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS account_id__ds__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS account_id__ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS account_id__ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS account_id__ds__year + , EXTRACT(year FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_month + , EXTRACT(week FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_week + , EXTRACT(day FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_day + , EXTRACT(dow FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_doy + , account_month_txns_src_10010.account_month AS account_id__account_month + , account_month_txns_src_10010.account_id + FROM ***************************.account_month_txns account_month_txns_src_10010 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] + SELECT + subq_6.ds_partitioned__day + , subq_6.account_id + , subq_6.customer_id__customer_name + FROM ( + -- Join Standard Outputs + SELECT + subq_3.ds_partitioned__day AS ds_partitioned__day + , subq_3.ds_partitioned__week AS ds_partitioned__week + , subq_3.ds_partitioned__month AS ds_partitioned__month + , subq_3.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_3.ds_partitioned__year AS ds_partitioned__year + , subq_3.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_week AS ds_partitioned__extract_week + , subq_3.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_3.account_id__ds_partitioned__day AS account_id__ds_partitioned__day + , subq_3.account_id__ds_partitioned__week AS account_id__ds_partitioned__week + , subq_3.account_id__ds_partitioned__month AS account_id__ds_partitioned__month + , subq_3.account_id__ds_partitioned__quarter AS account_id__ds_partitioned__quarter + , subq_3.account_id__ds_partitioned__year AS account_id__ds_partitioned__year + , subq_3.account_id__ds_partitioned__extract_year AS account_id__ds_partitioned__extract_year + , subq_3.account_id__ds_partitioned__extract_quarter AS account_id__ds_partitioned__extract_quarter + , subq_3.account_id__ds_partitioned__extract_month AS account_id__ds_partitioned__extract_month + , subq_3.account_id__ds_partitioned__extract_week AS account_id__ds_partitioned__extract_week + , subq_3.account_id__ds_partitioned__extract_day AS account_id__ds_partitioned__extract_day + , subq_3.account_id__ds_partitioned__extract_dow AS account_id__ds_partitioned__extract_dow + , subq_3.account_id__ds_partitioned__extract_doy AS account_id__ds_partitioned__extract_doy + , subq_3.bridge_account__ds_partitioned__day AS bridge_account__ds_partitioned__day + , subq_3.bridge_account__ds_partitioned__week AS bridge_account__ds_partitioned__week + , subq_3.bridge_account__ds_partitioned__month AS bridge_account__ds_partitioned__month + , subq_3.bridge_account__ds_partitioned__quarter AS bridge_account__ds_partitioned__quarter + , subq_3.bridge_account__ds_partitioned__year AS bridge_account__ds_partitioned__year + , subq_3.bridge_account__ds_partitioned__extract_year AS bridge_account__ds_partitioned__extract_year + , subq_3.bridge_account__ds_partitioned__extract_quarter AS bridge_account__ds_partitioned__extract_quarter + , subq_3.bridge_account__ds_partitioned__extract_month AS bridge_account__ds_partitioned__extract_month + , subq_3.bridge_account__ds_partitioned__extract_week AS bridge_account__ds_partitioned__extract_week + , subq_3.bridge_account__ds_partitioned__extract_day AS bridge_account__ds_partitioned__extract_day + , subq_3.bridge_account__ds_partitioned__extract_dow AS bridge_account__ds_partitioned__extract_dow + , subq_3.bridge_account__ds_partitioned__extract_doy AS bridge_account__ds_partitioned__extract_doy + , subq_5.ds_partitioned__day AS customer_id__ds_partitioned__day + , subq_5.ds_partitioned__week AS customer_id__ds_partitioned__week + , subq_5.ds_partitioned__month AS customer_id__ds_partitioned__month + , subq_5.ds_partitioned__quarter AS customer_id__ds_partitioned__quarter + , subq_5.ds_partitioned__year AS customer_id__ds_partitioned__year + , subq_5.ds_partitioned__extract_year AS customer_id__ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter AS customer_id__ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month AS customer_id__ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_week AS customer_id__ds_partitioned__extract_week + , subq_5.ds_partitioned__extract_day AS customer_id__ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow AS customer_id__ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy AS customer_id__ds_partitioned__extract_doy + , subq_3.account_id AS account_id + , subq_3.customer_id AS customer_id + , subq_3.account_id__customer_id AS account_id__customer_id + , subq_3.bridge_account__account_id AS bridge_account__account_id + , subq_3.bridge_account__customer_id AS bridge_account__customer_id + , subq_3.extra_dim AS extra_dim + , subq_3.account_id__extra_dim AS account_id__extra_dim + , subq_3.bridge_account__extra_dim AS bridge_account__extra_dim + , subq_5.customer_name AS customer_id__customer_name + , subq_5.customer_atomic_weight AS customer_id__customer_atomic_weight + FROM ( + -- Read Elements From Semantic Model 'bridge_table' + SELECT + bridge_table_src_10011.extra_dim + , bridge_table_src_10011.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_doy + , bridge_table_src_10011.extra_dim AS account_id__extra_dim + , bridge_table_src_10011.ds_partitioned AS account_id__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(week FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_week + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(dow FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , bridge_table_src_10011.extra_dim AS bridge_account__extra_dim + , bridge_table_src_10011.ds_partitioned AS bridge_account__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_month + , EXTRACT(week FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_week + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_day + , EXTRACT(dow FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy + , bridge_table_src_10011.account_id + , bridge_table_src_10011.customer_id + , bridge_table_src_10011.customer_id AS account_id__customer_id + , bridge_table_src_10011.account_id AS bridge_account__account_id + , bridge_table_src_10011.customer_id AS bridge_account__customer_id + FROM ***************************.bridge_table bridge_table_src_10011 + ) subq_3 + 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_week', + -- '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_week', + -- 'customer_id__ds_partitioned__extract_day', + -- 'customer_id__ds_partitioned__extract_dow', + -- 'customer_id__ds_partitioned__extract_doy', + -- 'customer_id'] + 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_week + , 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_week + , 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.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 ( + -- Read Elements From Semantic Model 'customer_table' + SELECT + customer_table_src_10013.customer_name + , customer_table_src_10013.customer_atomic_weight + , customer_table_src_10013.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_doy + , customer_table_src_10013.customer_name AS customer_id__customer_name + , customer_table_src_10013.customer_atomic_weight AS customer_id__customer_atomic_weight + , customer_table_src_10013.ds_partitioned AS customer_id__ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_month + , EXTRACT(week FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_week + , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_day + , EXTRACT(dow FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_doy + , customer_table_src_10013.customer_id + FROM ***************************.customer_table customer_table_src_10013 + ) subq_4 + ) subq_5 + ON + ( + subq_3.customer_id = subq_5.customer_id + ) AND ( + subq_3.ds_partitioned__day = subq_5.ds_partitioned__day + ) + ) subq_6 + ) subq_7 + ON + ( + subq_2.account_id = subq_7.account_id + ) AND ( + subq_2.ds_partitioned__day = subq_7.ds_partitioned__day + ) + ) subq_8 + ) subq_9 + GROUP BY + subq_9.account_id__customer_id__customer_name +) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql new file mode 100644 index 0000000000..ba4bf14fba --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql @@ -0,0 +1,35 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['txn_count', 'account_id__customer_id__customer_name'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + subq_18.customer_id__customer_name AS account_id__customer_id__customer_name + , SUM(account_month_txns_src_10010.txn_count) AS txn_count +FROM ***************************.account_month_txns account_month_txns_src_10010 +LEFT OUTER JOIN ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] + SELECT + bridge_table_src_10011.ds_partitioned AS ds_partitioned__day + , bridge_table_src_10011.account_id AS account_id + , customer_table_src_10013.customer_name AS customer_id__customer_name + FROM ***************************.bridge_table bridge_table_src_10011 + LEFT OUTER JOIN + ***************************.customer_table customer_table_src_10013 + ON + ( + bridge_table_src_10011.customer_id = customer_table_src_10013.customer_id + ) AND ( + bridge_table_src_10011.ds_partitioned = customer_table_src_10013.ds_partitioned + ) +) subq_18 +ON + ( + account_month_txns_src_10010.account_id = subq_18.account_id + ) AND ( + account_month_txns_src_10010.ds_partitioned = subq_18.ds_partitioned__day + ) +GROUP BY + subq_18.customer_id__customer_name diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql new file mode 100644 index 0000000000..54b108dd33 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql @@ -0,0 +1,572 @@ +-- Combine Metrics +SELECT + MAX(subq_5.bookings) AS bookings + , MAX(subq_11.listings) AS listings +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_4.bookings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_3.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings'] + SELECT + subq_2.bookings + FROM ( + -- Constrain Time Range to [2020-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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 +CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_10.listings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_9.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings'] + SELECT + subq_8.listings + FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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 + 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql new file mode 100644 index 0000000000..74dcbb71f8 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql @@ -0,0 +1,30 @@ +-- Combine Metrics +SELECT + MAX(subq_17.bookings) AS bookings + , MAX(subq_23.listings) AS listings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- Pass Only Elements: + -- ['bookings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' +) subq_17 +CROSS JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- Pass Only Elements: + -- ['listings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 + WHERE created_at BETWEEN '2020-01-01' AND '2020-01-01' +) subq_23 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql new file mode 100644 index 0000000000..a716977aaf --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql @@ -0,0 +1,971 @@ +-- Compute Metrics via Expressions +SELECT + subq_22.metric_time__day + , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day) AS metric_time__day + , subq_11.non_referred AS non_referred + , subq_16.instant AS instant + , subq_21.bookings AS bookings + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred + FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , subq_4.ref_bookings AS ref_bookings + , subq_9.bookings AS bookings + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.referred_bookings AS ref_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.referred_bookings) AS referred_bookings + FROM ( + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.referred_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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + ON + ( + subq_4.metric_time__day = subq_9.metric_time__day + ) OR ( + ( + subq_4.metric_time__day IS NULL + ) AND ( + subq_9.metric_time__day IS NULL + ) + ) + ) subq_10 + ) subq_11 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__day + , subq_15.instant_bookings AS instant + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__day + , SUM(subq_14.instant_bookings) AS instant_bookings + FROM ( + -- Pass Only Elements: + -- ['instant_bookings', 'metric_time__day'] + SELECT + subq_13.metric_time__day + , subq_13.instant_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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_12 + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__day + ) subq_15 + ) subq_16 + ON + ( + subq_11.metric_time__day = subq_16.metric_time__day + ) OR ( + ( + subq_11.metric_time__day IS NULL + ) AND ( + subq_16.metric_time__day IS NULL + ) + ) + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_20.metric_time__day + , subq_20.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_19.metric_time__day + , SUM(subq_19.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_18.metric_time__day + , subq_18.bookings + FROM ( + -- Metric Time Dimension 'ds' + 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_17 + ) subq_18 + ) subq_19 + GROUP BY + subq_19.metric_time__day + ) subq_20 + ) subq_21 + ON + ( + subq_11.metric_time__day = subq_21.metric_time__day + ) OR ( + ( + subq_11.metric_time__day IS NULL + ) AND ( + subq_21.metric_time__day IS NULL + ) + ) +) subq_22 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql new file mode 100644 index 0000000000..e45cf8bb70 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql @@ -0,0 +1,131 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day) AS metric_time__day + , subq_34.non_referred AS non_referred + , subq_39.instant AS instant + , subq_44.bookings AS bookings + FROM ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred + FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , subq_27.ref_bookings AS ref_bookings + , subq_32.bookings AS bookings + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(referred_bookings) AS ref_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_25 + GROUP BY + metric_time__day + ) subq_27 + INNER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_30 + GROUP BY + metric_time__day + ) subq_32 + ON + ( + subq_27.metric_time__day = subq_32.metric_time__day + ) OR ( + ( + subq_27.metric_time__day IS NULL + ) AND ( + subq_32.metric_time__day IS NULL + ) + ) + ) subq_33 + ) subq_34 + INNER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(instant_bookings) AS instant + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['instant_bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_37 + GROUP BY + metric_time__day + ) subq_39 + ON + ( + subq_34.metric_time__day = subq_39.metric_time__day + ) OR ( + ( + subq_34.metric_time__day IS NULL + ) AND ( + subq_39.metric_time__day IS NULL + ) + ) + INNER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_42 + GROUP BY + metric_time__day + ) subq_44 + ON + ( + subq_34.metric_time__day = subq_44.metric_time__day + ) OR ( + ( + subq_34.metric_time__day IS NULL + ) AND ( + subq_44.metric_time__day IS NULL + ) + ) +) subq_45 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql new file mode 100644 index 0000000000..a65895e8b1 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__extract_dow + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) AS metric_time__extract_dow + , subq_4.bookings AS bookings + , subq_12.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__extract_dow + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__extract_dow + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + subq_1.metric_time__extract_dow + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__extract_dow + ) subq_3 + ) subq_4 + INNER 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 + EXTRACT(dow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , 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_week AS ds__extract_week + , 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_week AS ds_partitioned__extract_week + , 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_week AS paid_at__extract_week + , 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_week AS booking__ds__extract_week + , 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_week AS booking__ds_partitioned__extract_week + , 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_week AS booking__paid_at__extract_week + , 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 ( + -- Date 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__extract_dow + ) subq_11 + ) subq_12 + ON + ( + subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + ) OR ( + ( + subq_4.metric_time__extract_dow IS NULL + ) AND ( + subq_12.metric_time__extract_dow IS NULL + ) + ) +) subq_13 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql new file mode 100644 index 0000000000..5f6ec1ee79 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__extract_dow + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) AS metric_time__extract_dow + , subq_18.bookings AS bookings + , subq_26.bookings_2_weeks_ago AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__extract_dow + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + EXTRACT(dow FROM ds) AS metric_time__extract_dow + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__extract_dow + ) subq_18 + INNER JOIN ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + EXTRACT(dow FROM subq_22.ds) AS metric_time__extract_dow + , SUM(subq_20.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_22 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + GROUP BY + EXTRACT(dow FROM subq_22.ds) + ) subq_26 + ON + ( + subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow + ) OR ( + ( + subq_18.metric_time__extract_dow IS NULL + ) AND ( + subq_26.metric_time__extract_dow IS NULL + ) + ) +) subq_27 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql new file mode 100644 index 0000000000..d6632b499f --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql @@ -0,0 +1,130 @@ +-- Order By ['ds__day', 'bookings'] +SELECT + subq_3.ds__day + , subq_3.is_instant + , subq_3.bookings +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_2.ds__day + , subq_2.is_instant + , subq_2.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_1.ds__day + , subq_1.is_instant + , SUM(subq_1.bookings) AS bookings + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + GROUP BY + subq_1.ds__day + , subq_1.is_instant + ) subq_2 +) subq_3 +ORDER BY subq_3.ds__day, subq_3.bookings DESC diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql new file mode 100644 index 0000000000..efe34b261f --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +-- Order By ['ds__day', 'bookings'] +SELECT + ds__day + , is_instant + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'ds__day'] + SELECT + ds AS ds__day + , is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_5 +GROUP BY + ds__day + , is_instant +ORDER BY ds__day, bookings DESC diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql new file mode 100644 index 0000000000..44cff4ab94 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql @@ -0,0 +1,259 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.user__home_state + , subq_7.identity_verifications +FROM ( + -- Aggregate Measures + SELECT + subq_6.user__home_state + , SUM(subq_6.identity_verifications) AS identity_verifications + FROM ( + -- Pass Only Elements: + -- ['identity_verifications', 'user__home_state'] + SELECT + subq_5.user__home_state + , subq_5.identity_verifications + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds_partitioned__day AS ds_partitioned__day + , subq_4.ds_partitioned__day AS user__ds_partitioned__day + , subq_2.user AS user + , subq_4.home_state AS user__home_state + , subq_2.identity_verifications AS identity_verifications + FROM ( + -- Pass Only Elements: + -- ['identity_verifications', 'ds_partitioned__day', 'user'] + 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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 + , id_verifications_src_10003.ds AS ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds) AS ds__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy + , id_verifications_src_10003.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type + , id_verifications_src_10003.ds AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds) AS verification__ds__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy + , id_verifications_src_10003.ds_partitioned AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type AS verification__verification_type + , id_verifications_src_10003.verification_id AS verification + , id_verifications_src_10003.user_id AS user + , id_verifications_src_10003.user_id AS verification__user + FROM ***************************.fct_id_verifications id_verifications_src_10003 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state', 'ds_partitioned__day', 'user'] + SELECT + subq_3.ds_partitioned__day + , subq_3.user + , subq_3.home_state + FROM ( + -- Read Elements From Semantic Model 'users_ds_source' + SELECT + users_ds_source_src_10007.ds AS ds__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_10007.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds) AS ds__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.ds) AS ds__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.ds) AS ds__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS ds__extract_doy + , users_ds_source_src_10007.created_at AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS created_at__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.created_at) AS created_at__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS created_at__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS created_at__extract_doy + , users_ds_source_src_10007.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_10007.home_state + , users_ds_source_src_10007.ds AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_10007.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds) AS user__ds__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.ds) AS user__ds__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.ds) AS user__ds__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS user__ds__extract_doy + , users_ds_source_src_10007.created_at AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_doy + , users_ds_source_src_10007.ds_partitioned AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(week FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_week + , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(dow FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_10007.home_state AS user__home_state + , users_ds_source_src_10007.user_id AS user + FROM ***************************.dim_users users_ds_source_src_10007 + ) subq_3 + ) subq_4 + ON + ( + subq_2.user = subq_4.user + ) AND ( + subq_2.ds_partitioned__day = subq_4.ds_partitioned__day + ) + ) subq_5 + ) subq_6 + GROUP BY + subq_6.user__home_state +) subq_7 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql new file mode 100644 index 0000000000..66ea172ae7 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql @@ -0,0 +1,29 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['identity_verifications', 'user__home_state'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + users_ds_source_src_10007.home_state AS user__home_state + , SUM(subq_10.identity_verifications) AS identity_verifications +FROM ( + -- Read Elements From Semantic Model 'id_verifications' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['identity_verifications', 'ds_partitioned__day', 'user'] + SELECT + ds_partitioned AS ds_partitioned__day + , user_id AS user + , 1 AS identity_verifications + FROM ***************************.fct_id_verifications id_verifications_src_10003 +) subq_10 +LEFT OUTER JOIN + ***************************.dim_users users_ds_source_src_10007 +ON + ( + subq_10.user = users_ds_source_src_10007.user_id + ) AND ( + subq_10.ds_partitioned__day = users_ds_source_src_10007.ds_partitioned + ) +GROUP BY + users_ds_source_src_10007.home_state diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql new file mode 100644 index 0000000000..33fc914795 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql @@ -0,0 +1,112 @@ +-- Join on MIN(ds) and [] grouping by None +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_week AS ds__extract_week + , 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.account__ds__day AS account__ds__day + , subq_0.account__ds__week AS account__ds__week + , subq_0.account__ds__month AS account__ds__month + , subq_0.account__ds__quarter AS account__ds__quarter + , subq_0.account__ds__year AS account__ds__year + , subq_0.account__ds__extract_year AS account__ds__extract_year + , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_0.account__ds__extract_month AS account__ds__extract_month + , subq_0.account__ds__extract_week AS account__ds__extract_week + , subq_0.account__ds__extract_day AS account__ds__extract_day + , subq_0.account__ds__extract_dow AS account__ds__extract_dow + , subq_0.account__ds__extract_doy AS account__ds__extract_doy + , subq_0.user AS user + , subq_0.account__user AS account__user + , subq_0.account_type AS account_type + , subq_0.account__account_type AS account__account_type + , subq_0.account_balance AS account_balance + , subq_0.total_account_balance_first_day AS total_account_balance_first_day + , subq_0.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_0 +INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_1.ds__day) AS ds__day__complete + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 + ) subq_1 +) subq_2 +ON + subq_0.ds__day = subq_2.ds__day__complete diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql new file mode 100644 index 0000000000..d90abbd294 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql @@ -0,0 +1,78 @@ +-- Join on MIN(ds) and [] grouping by None +SELECT + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_week AS ds__extract_week + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.account__ds__day AS account__ds__day + , subq_3.account__ds__week AS account__ds__week + , subq_3.account__ds__month AS account__ds__month + , subq_3.account__ds__quarter AS account__ds__quarter + , subq_3.account__ds__year AS account__ds__year + , subq_3.account__ds__extract_year AS account__ds__extract_year + , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_3.account__ds__extract_month AS account__ds__extract_month + , subq_3.account__ds__extract_week AS account__ds__extract_week + , subq_3.account__ds__extract_day AS account__ds__extract_day + , subq_3.account__ds__extract_dow AS account__ds__extract_dow + , subq_3.account__ds__extract_doy AS account__ds__extract_doy + , subq_3.user AS user + , subq_3.account__user AS account__user + , subq_3.account_type AS account_type + , subq_3.account__account_type AS account__account_type + , subq_3.account_balance AS account_balance + , subq_3.total_account_balance_first_day AS total_account_balance_first_day + , subq_3.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + account_balance + , account_balance AS total_account_balance_first_day + , account_balance AS current_account_balance_by_user + , ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , account_type + , ds AS account__ds__day + , DATE_TRUNC('week', ds) AS account__ds__week + , DATE_TRUNC('month', ds) AS account__ds__month + , DATE_TRUNC('quarter', ds) AS account__ds__quarter + , DATE_TRUNC('year', ds) AS account__ds__year + , EXTRACT(year FROM ds) AS account__ds__extract_year + , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter + , EXTRACT(month FROM ds) AS account__ds__extract_month + , EXTRACT(week FROM ds) AS account__ds__extract_week + , EXTRACT(day FROM ds) AS account__ds__extract_day + , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(doy FROM ds) AS account__ds__extract_doy + , account_type AS account__account_type + , user_id AS user + , user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_3 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Filter row on MIN(ds__day) + SELECT + MIN(ds) AS ds__day__complete + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_5 +ON + subq_3.ds__day = subq_5.ds__day__complete diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql new file mode 100644 index 0000000000..dc98b44d95 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql @@ -0,0 +1,119 @@ +-- Join on MAX(ds) and ['user'] grouping by None +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_week AS ds__extract_week + , 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.account__ds__day AS account__ds__day + , subq_0.account__ds__week AS account__ds__week + , subq_0.account__ds__month AS account__ds__month + , subq_0.account__ds__quarter AS account__ds__quarter + , subq_0.account__ds__year AS account__ds__year + , subq_0.account__ds__extract_year AS account__ds__extract_year + , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_0.account__ds__extract_month AS account__ds__extract_month + , subq_0.account__ds__extract_week AS account__ds__extract_week + , subq_0.account__ds__extract_day AS account__ds__extract_day + , subq_0.account__ds__extract_dow AS account__ds__extract_dow + , subq_0.account__ds__extract_doy AS account__ds__extract_doy + , subq_0.user AS user + , subq_0.account__user AS account__user + , subq_0.account_type AS account_type + , subq_0.account__account_type AS account__account_type + , subq_0.account_balance AS account_balance + , subq_0.total_account_balance_first_day AS total_account_balance_first_day + , subq_0.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_0 +INNER JOIN ( + -- Filter row on MAX(ds__day) + SELECT + subq_1.user + , MAX(subq_1.ds__day) AS ds__day__complete + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 + ) subq_1 + GROUP BY + subq_1.user +) subq_2 +ON + ( + subq_0.ds__day = subq_2.ds__day__complete + ) AND ( + subq_0.user = subq_2.user + ) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql new file mode 100644 index 0000000000..d723157d2a --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql @@ -0,0 +1,85 @@ +-- Join on MAX(ds) and ['user'] grouping by None +SELECT + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_week AS ds__extract_week + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.account__ds__day AS account__ds__day + , subq_3.account__ds__week AS account__ds__week + , subq_3.account__ds__month AS account__ds__month + , subq_3.account__ds__quarter AS account__ds__quarter + , subq_3.account__ds__year AS account__ds__year + , subq_3.account__ds__extract_year AS account__ds__extract_year + , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_3.account__ds__extract_month AS account__ds__extract_month + , subq_3.account__ds__extract_week AS account__ds__extract_week + , subq_3.account__ds__extract_day AS account__ds__extract_day + , subq_3.account__ds__extract_dow AS account__ds__extract_dow + , subq_3.account__ds__extract_doy AS account__ds__extract_doy + , subq_3.user AS user + , subq_3.account__user AS account__user + , subq_3.account_type AS account_type + , subq_3.account__account_type AS account__account_type + , subq_3.account_balance AS account_balance + , subq_3.total_account_balance_first_day AS total_account_balance_first_day + , subq_3.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + account_balance + , account_balance AS total_account_balance_first_day + , account_balance AS current_account_balance_by_user + , ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , account_type + , ds AS account__ds__day + , DATE_TRUNC('week', ds) AS account__ds__week + , DATE_TRUNC('month', ds) AS account__ds__month + , DATE_TRUNC('quarter', ds) AS account__ds__quarter + , DATE_TRUNC('year', ds) AS account__ds__year + , EXTRACT(year FROM ds) AS account__ds__extract_year + , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter + , EXTRACT(month FROM ds) AS account__ds__extract_month + , EXTRACT(week FROM ds) AS account__ds__extract_week + , EXTRACT(day FROM ds) AS account__ds__extract_day + , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(doy FROM ds) AS account__ds__extract_doy + , account_type AS account__account_type + , user_id AS user + , user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_3 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Filter row on MAX(ds__day) + SELECT + user_id AS user + , MAX(ds) AS ds__day__complete + FROM ***************************.fct_accounts accounts_source_src_10000 + GROUP BY + user_id +) subq_5 +ON + ( + subq_3.ds__day = subq_5.ds__day__complete + ) AND ( + subq_3.user = subq_5.user + ) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql new file mode 100644 index 0000000000..95274f2863 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql @@ -0,0 +1,115 @@ +-- Join on MIN(ds) and [] grouping by ds +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_week AS ds__extract_week + , 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.account__ds__day AS account__ds__day + , subq_0.account__ds__week AS account__ds__week + , subq_0.account__ds__month AS account__ds__month + , subq_0.account__ds__quarter AS account__ds__quarter + , subq_0.account__ds__year AS account__ds__year + , subq_0.account__ds__extract_year AS account__ds__extract_year + , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_0.account__ds__extract_month AS account__ds__extract_month + , subq_0.account__ds__extract_week AS account__ds__extract_week + , subq_0.account__ds__extract_day AS account__ds__extract_day + , subq_0.account__ds__extract_dow AS account__ds__extract_dow + , subq_0.account__ds__extract_doy AS account__ds__extract_doy + , subq_0.user AS user + , subq_0.account__user AS account__user + , subq_0.account_type AS account_type + , subq_0.account__account_type AS account__account_type + , subq_0.account_balance AS account_balance + , subq_0.total_account_balance_first_day AS total_account_balance_first_day + , subq_0.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_0 +INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + subq_1.ds__week + , MIN(subq_1.ds__day) AS ds__day__complete + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_10000.account_balance + , accounts_source_src_10000.account_balance AS total_account_balance_first_day + , accounts_source_src_10000.account_balance AS current_account_balance_by_user + , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy + , accounts_source_src_10000.account_type + , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month + , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week + , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day + , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy + , accounts_source_src_10000.account_type AS account__account_type + , accounts_source_src_10000.user_id AS user + , accounts_source_src_10000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 + ) subq_1 + GROUP BY + subq_1.ds__week +) subq_2 +ON + subq_0.ds__day = subq_2.ds__day__complete diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..e0c877bdf1 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql @@ -0,0 +1,81 @@ +-- Join on MIN(ds) and [] grouping by ds +SELECT + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_week AS ds__extract_week + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.account__ds__day AS account__ds__day + , subq_3.account__ds__week AS account__ds__week + , subq_3.account__ds__month AS account__ds__month + , subq_3.account__ds__quarter AS account__ds__quarter + , subq_3.account__ds__year AS account__ds__year + , subq_3.account__ds__extract_year AS account__ds__extract_year + , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter + , subq_3.account__ds__extract_month AS account__ds__extract_month + , subq_3.account__ds__extract_week AS account__ds__extract_week + , subq_3.account__ds__extract_day AS account__ds__extract_day + , subq_3.account__ds__extract_dow AS account__ds__extract_dow + , subq_3.account__ds__extract_doy AS account__ds__extract_doy + , subq_3.user AS user + , subq_3.account__user AS account__user + , subq_3.account_type AS account_type + , subq_3.account__account_type AS account__account_type + , subq_3.account_balance AS account_balance + , subq_3.total_account_balance_first_day AS total_account_balance_first_day + , subq_3.current_account_balance_by_user AS current_account_balance_by_user +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + account_balance + , account_balance AS total_account_balance_first_day + , account_balance AS current_account_balance_by_user + , ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , account_type + , ds AS account__ds__day + , DATE_TRUNC('week', ds) AS account__ds__week + , DATE_TRUNC('month', ds) AS account__ds__month + , DATE_TRUNC('quarter', ds) AS account__ds__quarter + , DATE_TRUNC('year', ds) AS account__ds__year + , EXTRACT(year FROM ds) AS account__ds__extract_year + , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter + , EXTRACT(month FROM ds) AS account__ds__extract_month + , EXTRACT(week FROM ds) AS account__ds__extract_week + , EXTRACT(day FROM ds) AS account__ds__extract_day + , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(doy FROM ds) AS account__ds__extract_doy + , account_type AS account__account_type + , user_id AS user + , user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_10000 +) subq_3 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Filter row on MIN(ds__day) + SELECT + DATE_TRUNC('week', ds) AS ds__week + , MIN(ds) AS ds__day__complete + FROM ***************************.fct_accounts accounts_source_src_10000 + GROUP BY + DATE_TRUNC('week', ds) +) subq_5 +ON + subq_3.ds__day = subq_5.ds__day__complete diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql new file mode 100644 index 0000000000..3869c341c5 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql @@ -0,0 +1,227 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.metric_time__extract_dow + , subq_3.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__extract_dow + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + subq_1.metric_time__extract_dow + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__extract_dow +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql new file mode 100644 index 0000000000..33b25a725c --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__extract_dow + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + EXTRACT(dow FROM ds) AS metric_time__extract_dow + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_6 +GROUP BY + metric_time__extract_dow diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql new file mode 100644 index 0000000000..b1321ec748 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql @@ -0,0 +1,258 @@ +-- 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_week + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.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_week + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'metric_time__extract_week', + -- 'metric_time__extract_month', + -- 'metric_time__extract_quarter', + -- '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_week + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + 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_week + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy +) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql new file mode 100644 index 0000000000..402fb4f517 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__extract_year + , metric_time__extract_quarter + , metric_time__extract_month + , metric_time__extract_week + , metric_time__extract_day + , metric_time__extract_dow + , metric_time__extract_doy + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'metric_time__extract_week', + -- 'metric_time__extract_month', + -- 'metric_time__extract_quarter', + -- 'metric_time__extract_year'] + SELECT + EXTRACT(year FROM ds) AS metric_time__extract_year + , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter + , EXTRACT(month FROM ds) AS metric_time__extract_month + , EXTRACT(week FROM ds) AS metric_time__extract_week + , EXTRACT(day FROM ds) AS metric_time__extract_day + , EXTRACT(dow FROM ds) AS metric_time__extract_dow + , EXTRACT(doy FROM ds) AS metric_time__extract_doy + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_6 +GROUP BY + metric_time__extract_year + , metric_time__extract_quarter + , metric_time__extract_month + , metric_time__extract_week + , metric_time__extract_day + , metric_time__extract_dow + , metric_time__extract_doy diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql new file mode 100644 index 0000000000..9c6e0a2676 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql @@ -0,0 +1,184 @@ +-- Join Standard Outputs +SELECT + subq_1.listing AS listing + , subq_1.bookings AS bookings +FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 +) subq_1 +LEFT OUTER JOIN ( + -- 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_2 +) subq_3 +ON + subq_1.listing = subq_3.listing diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql new file mode 100644 index 0000000000..480a2c9f56 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Join Standard Outputs +SELECT + subq_5.listing AS listing + , subq_5.bookings AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'listing'] + SELECT + listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_5 +LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 +ON + subq_5.listing = listings_latest_src_10004.listing_id diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql new file mode 100644 index 0000000000..b9ae7f84a4 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql @@ -0,0 +1,97 @@ +-- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql new file mode 100644 index 0000000000..d1560d9ab0 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql @@ -0,0 +1,97 @@ +-- Read Elements From Semantic Model 'bookings_source' +SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , booking_value + , booking_value AS max_booking_value + , booking_value AS min_booking_value + , guest_id AS bookers + , booking_value AS average_booking_value + , booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , booking_value AS median_booking_value + , booking_value AS booking_value_p99 + , booking_value AS discrete_booking_value_p99 + , booking_value AS approximate_continuous_booking_value_p99 + , booking_value AS approximate_discrete_booking_value_p99 + , is_instant + , ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy + , paid_at AS paid_at__day + , DATE_TRUNC('week', paid_at) AS paid_at__week + , DATE_TRUNC('month', paid_at) AS paid_at__month + , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter + , DATE_TRUNC('year', paid_at) AS paid_at__year + , EXTRACT(year FROM paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS paid_at__extract_month + , EXTRACT(week FROM paid_at) AS paid_at__extract_week + , EXTRACT(day FROM paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy + , is_instant AS booking__is_instant + , ds AS booking__ds__day + , DATE_TRUNC('week', ds) AS booking__ds__week + , DATE_TRUNC('month', ds) AS booking__ds__month + , DATE_TRUNC('quarter', ds) AS booking__ds__quarter + , DATE_TRUNC('year', ds) AS booking__ds__year + , EXTRACT(year FROM ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM ds) AS booking__ds__extract_month + , EXTRACT(week FROM ds) AS booking__ds__extract_week + , EXTRACT(day FROM ds) AS booking__ds__extract_day + , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM ds) AS booking__ds__extract_doy + , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy + , paid_at AS booking__paid_at__day + , DATE_TRUNC('week', paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', paid_at) AS booking__paid_at__year + , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy + , listing_id AS listing + , guest_id AS guest + , host_id AS host + , listing_id AS booking__listing + , guest_id AS booking__guest + , host_id AS booking__host +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql new file mode 100644 index 0000000000..ca1e6ab7a9 --- /dev/null +++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql @@ -0,0 +1,4 @@ +-- Test Approximate Continuous Percentile Expression +SELECT + approx_quantile(a.col0, 0.5) AS col0_percentile +FROM foo.bar a diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql new file mode 100644 index 0000000000..c47396730d --- /dev/null +++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql @@ -0,0 +1,4 @@ +-- Test Cast to Timestamp Expression +SELECT + CAST('2020-01-01' AS TIMESTAMP) AS col0 +FROM foo.bar a diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql new file mode 100644 index 0000000000..ccdd1213e8 --- /dev/null +++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql @@ -0,0 +1,4 @@ +-- Test Generate UUID Expression +SELECT + uuid() AS uuid +FROM foo.bar a diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql new file mode 100644 index 0000000000..e9ab8e5153 --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql @@ -0,0 +1,194 @@ +-- Metric Time Dimension 'paid_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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy + , subq_0.paid_at__day AS metric_time__day + , subq_0.paid_at__week AS metric_time__week + , subq_0.paid_at__month AS metric_time__month + , subq_0.paid_at__quarter AS metric_time__quarter + , subq_0.paid_at__year AS metric_time__year + , subq_0.paid_at__extract_year AS metric_time__extract_year + , subq_0.paid_at__extract_quarter AS metric_time__extract_quarter + , subq_0.paid_at__extract_month AS metric_time__extract_month + , subq_0.paid_at__extract_week AS metric_time__extract_week + , subq_0.paid_at__extract_day AS metric_time__extract_day + , subq_0.paid_at__extract_dow AS metric_time__extract_dow + , subq_0.paid_at__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.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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_0 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql new file mode 100644 index 0000000000..00e036ec03 --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql @@ -0,0 +1,97 @@ +-- Read Elements From Semantic Model 'bookings_source' +-- Metric Time Dimension 'paid_at' +SELECT + ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy + , paid_at AS paid_at__day + , DATE_TRUNC('week', paid_at) AS paid_at__week + , DATE_TRUNC('month', paid_at) AS paid_at__month + , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter + , DATE_TRUNC('year', paid_at) AS paid_at__year + , EXTRACT(year FROM paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS paid_at__extract_month + , EXTRACT(week FROM paid_at) AS paid_at__extract_week + , EXTRACT(day FROM paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy + , ds AS booking__ds__day + , DATE_TRUNC('week', ds) AS booking__ds__week + , DATE_TRUNC('month', ds) AS booking__ds__month + , DATE_TRUNC('quarter', ds) AS booking__ds__quarter + , DATE_TRUNC('year', ds) AS booking__ds__year + , EXTRACT(year FROM ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM ds) AS booking__ds__extract_month + , EXTRACT(week FROM ds) AS booking__ds__extract_week + , EXTRACT(day FROM ds) AS booking__ds__extract_day + , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM ds) AS booking__ds__extract_doy + , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy + , paid_at AS booking__paid_at__day + , DATE_TRUNC('week', paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', paid_at) AS booking__paid_at__year + , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy + , paid_at AS metric_time__day + , DATE_TRUNC('week', paid_at) AS metric_time__week + , DATE_TRUNC('month', paid_at) AS metric_time__month + , DATE_TRUNC('quarter', paid_at) AS metric_time__quarter + , DATE_TRUNC('year', paid_at) AS metric_time__year + , EXTRACT(year FROM paid_at) AS metric_time__extract_year + , EXTRACT(quarter FROM paid_at) AS metric_time__extract_quarter + , EXTRACT(month FROM paid_at) AS metric_time__extract_month + , EXTRACT(week FROM paid_at) AS metric_time__extract_week + , EXTRACT(day FROM paid_at) AS metric_time__extract_day + , EXTRACT(dow FROM paid_at) AS metric_time__extract_dow + , EXTRACT(doy FROM paid_at) AS metric_time__extract_doy + , listing_id AS listing + , guest_id AS guest + , host_id AS host + , listing_id AS booking__listing + , guest_id AS booking__guest + , host_id AS booking__host + , is_instant + , is_instant AS booking__is_instant + , booking_value AS booking_payments +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql new file mode 100644 index 0000000000..e2cc747ae2 --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql @@ -0,0 +1,206 @@ +-- 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_0 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql new file mode 100644 index 0000000000..c6d742fae0 --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql @@ -0,0 +1,109 @@ +-- Read Elements From Semantic Model 'bookings_source' +-- Metric Time Dimension 'ds' +SELECT + ds AS ds__day + , DATE_TRUNC('week', ds) AS ds__week + , DATE_TRUNC('month', ds) AS ds__month + , DATE_TRUNC('quarter', ds) AS ds__quarter + , DATE_TRUNC('year', ds) AS ds__year + , EXTRACT(year FROM ds) AS ds__extract_year + , EXTRACT(quarter FROM ds) AS ds__extract_quarter + , EXTRACT(month FROM ds) AS ds__extract_month + , EXTRACT(week FROM ds) AS ds__extract_week + , EXTRACT(day FROM ds) AS ds__extract_day + , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(doy FROM ds) AS ds__extract_doy + , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy + , paid_at AS paid_at__day + , DATE_TRUNC('week', paid_at) AS paid_at__week + , DATE_TRUNC('month', paid_at) AS paid_at__month + , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter + , DATE_TRUNC('year', paid_at) AS paid_at__year + , EXTRACT(year FROM paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS paid_at__extract_month + , EXTRACT(week FROM paid_at) AS paid_at__extract_week + , EXTRACT(day FROM paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy + , ds AS booking__ds__day + , DATE_TRUNC('week', ds) AS booking__ds__week + , DATE_TRUNC('month', ds) AS booking__ds__month + , DATE_TRUNC('quarter', ds) AS booking__ds__quarter + , DATE_TRUNC('year', ds) AS booking__ds__year + , EXTRACT(year FROM ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM ds) AS booking__ds__extract_month + , EXTRACT(week FROM ds) AS booking__ds__extract_week + , EXTRACT(day FROM ds) AS booking__ds__extract_day + , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM ds) AS booking__ds__extract_doy + , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy + , paid_at AS booking__paid_at__day + , DATE_TRUNC('week', paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', paid_at) AS booking__paid_at__year + , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy + , ds AS metric_time__day + , DATE_TRUNC('week', ds) AS metric_time__week + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('quarter', ds) AS metric_time__quarter + , DATE_TRUNC('year', ds) AS metric_time__year + , EXTRACT(year FROM ds) AS metric_time__extract_year + , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter + , EXTRACT(month FROM ds) AS metric_time__extract_month + , EXTRACT(week FROM ds) AS metric_time__extract_week + , EXTRACT(day FROM ds) AS metric_time__extract_day + , EXTRACT(dow FROM ds) AS metric_time__extract_dow + , EXTRACT(doy FROM ds) AS metric_time__extract_doy + , listing_id AS listing + , guest_id AS guest + , host_id AS host + , listing_id AS booking__listing + , guest_id AS booking__guest + , host_id AS booking__host + , is_instant + , is_instant AS booking__is_instant + , 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , booking_value + , booking_value AS max_booking_value + , booking_value AS min_booking_value + , guest_id AS bookers + , booking_value AS average_booking_value + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , booking_value AS median_booking_value + , booking_value AS booking_value_p99 + , booking_value AS discrete_booking_value_p99 + , booking_value AS approximate_continuous_booking_value_p99 + , booking_value AS approximate_discrete_booking_value_p99 +FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql new file mode 100644 index 0000000000..c88105f92d --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql @@ -0,0 +1,455 @@ +-- Combine Metrics +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 +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_8.metric_time__day + , subq_8.booking_payments + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.booking_payments) AS booking_payments + FROM ( + -- Pass Only Elements: + -- ['booking_payments', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.booking_payments + FROM ( + -- Metric Time Dimension 'paid_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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week + , 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_week AS metric_time__extract_week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..0a8efb1bc9 --- /dev/null +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Combine Metrics +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 +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_12 + GROUP BY + metric_time__day +) subq_14 +FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'paid_at' + -- Pass Only Elements: + -- ['booking_payments', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + paid_at AS metric_time__day + , SUM(booking_value) AS booking_payments + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + paid_at +) subq_19 +ON + subq_14.metric_time__day = subq_19.metric_time__day +GROUP BY + COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql new file mode 100644 index 0000000000..c7949f8a59 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__day + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_1 +) subq_2 +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql new file mode 100644 index 0000000000..701465ead6 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql @@ -0,0 +1,19 @@ +CREATE TABLE ***************************.test_table AS ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + ds AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_1 + ) subq_2 + GROUP BY + metric_time__day +) diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql new file mode 100644 index 0000000000..94a467a61a --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql @@ -0,0 +1,4 @@ +-- test0 +SELECT + SUM(1) AS bookings +FROM demo.fct_bookings a diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql new file mode 100644 index 0000000000..4f2811f3ab --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql @@ -0,0 +1,6 @@ +-- test1 +SELECT + SUM(1) AS bookings + , b.country AS user__country + , c.country AS listing__country +FROM demo.fct_bookings a diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql new file mode 100644 index 0000000000..9084cacd9c --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql @@ -0,0 +1,10 @@ +-- test2 +SELECT + SUM(1) AS bookings + , b.country AS user__country + , c.country AS listing__country +FROM demo.fct_bookings a +LEFT OUTER JOIN + demo.dim_users b +ON + a.user_id = b.user_id diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql new file mode 100644 index 0000000000..e283f191ed --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql @@ -0,0 +1,14 @@ +-- test3 +SELECT + SUM(1) AS bookings + , b.country AS user__country + , c.country AS listing__country +FROM demo.fct_bookings a +LEFT OUTER JOIN + demo.dim_users b +ON + a.user_id = b.user_id +LEFT OUTER JOIN + demo.dim_listings c +ON + a.user_id = c.user_id diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql new file mode 100644 index 0000000000..50c2a20f46 --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql @@ -0,0 +1,16 @@ +-- test4 +SELECT + SUM(1) AS bookings + , b.country AS user__country + , c.country AS listing__country +FROM demo.fct_bookings a +LEFT OUTER JOIN + demo.dim_users b +ON + a.user_id = b.user_id +LEFT OUTER JOIN + demo.dim_listings c +ON + a.user_id = c.user_id +GROUP BY + b.country diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql new file mode 100644 index 0000000000..98affe9d30 --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql @@ -0,0 +1,17 @@ +-- test5 +SELECT + SUM(1) AS bookings + , b.country AS user__country + , c.country AS listing__country +FROM demo.fct_bookings a +LEFT OUTER JOIN + demo.dim_users b +ON + a.user_id = b.user_id +LEFT OUTER JOIN + demo.dim_listings c +ON + a.user_id = c.user_id +GROUP BY + b.country + , c.country diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql new file mode 100644 index 0000000000..5720a09db8 --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql @@ -0,0 +1,5 @@ +-- test0 +SELECT + a.bookings +FROM demo.fct_bookings a +LIMIT 1 diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql new file mode 100644 index 0000000000..bef477c2b8 --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql @@ -0,0 +1,6 @@ +-- test0 +SELECT + a.booking_value + , a.bookings +FROM demo.fct_bookings a +ORDER BY a.booking_value, a.bookings DESC diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql new file mode 100644 index 0000000000..0f17ba24b2 --- /dev/null +++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql @@ -0,0 +1,5 @@ +-- test0 +SELECT + a.booking_value +FROM demo.fct_bookings a +WHERE a.booking_value > 100 diff --git a/pyproject.toml b/pyproject.toml index 9f77994289..34de456794 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,6 +72,11 @@ sql-client-packages = [ "SQLAlchemy~=1.4.42", "sqlalchemy2-stubs~=0.0.2a21", ] +trino-sql-client-packages = [ + "SQLAlchemy~=1.4.42", + "sqlalchemy2-stubs~=0.0.2a21", + "trino~=0.327.0", +] dbt-postgres = [ "dbt-postgres~=1.7.0", @@ -97,6 +102,10 @@ dbt-duckdb = [ "dbt-duckdb~=1.7.0", ] +dbt-trino = [ + "dbt-trino~=1.6.0", +] + [tool.hatch.build.targets.sdist] exclude = [ "/.github", @@ -181,6 +190,18 @@ features = [ "sql-client-packages", ] +[tool.hatch.envs.trino-env.env-vars] + MF_TEST_ADAPTER_TYPE="trino" + MF_SQL_ENGINE_URL="trino://trino@localhost:8080/memory" + +[tool.hatch.envs.trino-env] +description = "Dev environment for working with the Trino adapter" +features = [ + "dev-packages", + "dbt-trino", + "trino-sql-client-packages", +] + [tool.black] line-length = 120 From cfd11c38bbbbe133655cac84c3bc9b6c5d732fb4 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Thu, 5 Oct 2023 15:02:22 -0600 Subject: [PATCH 02/18] lint --- metricflow/sql/render/trino.py | 3 ++- .../test/fixtures/dbt_projects/metricflow_testing/profiles.yml | 2 +- metricflow/test/fixtures/setup_fixtures.py | 1 - metricflow/test/fixtures/sql_client_fixtures.py | 3 ++- .../test/fixtures/sql_clients/adapter_backed_ddl_client.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index b08e217268..349c0bfa8f 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -21,6 +21,7 @@ SqlTimeDeltaExpression, ) + class TrinoSqlExpressionRenderer(DefaultSqlExpressionRenderer): """Expression renderer for the Trino engine.""" @@ -112,4 +113,4 @@ class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer): @property @override def expr_renderer(self) -> SqlExpressionRenderer: - return self.EXPR_RENDERER \ No newline at end of file + return self.EXPR_RENDERER diff --git a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml index ca06dd4f57..99316d5df8 100644 --- a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml +++ b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml @@ -77,4 +77,4 @@ trino: user: "{{ env_var('DBT_ENV_SECRET_USER') }}" password: "{{ env_var('DBT_ENV_SECRET_PASSWORD') }}" catalog: "{{ env_var('DBT_ENV_SECRET_CATALOG') }}" - schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}" \ No newline at end of file + schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}" diff --git a/metricflow/test/fixtures/setup_fixtures.py b/metricflow/test/fixtures/setup_fixtures.py index 2109dbc506..9c936d0f22 100644 --- a/metricflow/test/fixtures/setup_fixtures.py +++ b/metricflow/test/fixtures/setup_fixtures.py @@ -20,7 +20,6 @@ logger = logging.getLogger(__name__) - @dataclass class MetricFlowTestSessionState: """State that is shared between tests during a testing session.""" diff --git a/metricflow/test/fixtures/sql_client_fixtures.py b/metricflow/test/fixtures/sql_client_fixtures.py index 7968f5a86e..6295484379 100644 --- a/metricflow/test/fixtures/sql_client_fixtures.py +++ b/metricflow/test/fixtures/sql_client_fixtures.py @@ -123,15 +123,16 @@ def __configure_databricks_env_from_url(url: str, password: str, schema: str) -> os.environ[DBT_ENV_SECRET_HTTP_PATH] = http_path __configure_test_env_from_url(url_pieces[0], password=password, schema=schema) + def __configure_trino_env_from_url(url: str, password: str, schema: str) -> None: """Databricks has a custom http path attribute, which we have encoded into a SqlAlchemy-like URL appendage. This custom parsing was ported from our original client implementation for backwards compatibility with the existing CI job configurations. """ - pass + def __initialize_dbt() -> None: """Invoke the dbt runner from the appropriate directory so we can fetch the relevant adapter. diff --git a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py index d9fa7cd2d1..55b09819a7 100644 --- a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py +++ b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py @@ -103,7 +103,7 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str: elif dtype == "float64": return self._sql_query_plan_renderer.expr_renderer.double_data_type elif dtype == "datetime64[ns]": - if self.sql_engine_type is SqlEngine.TRINO: # mptrino does implicitly cast datetime to timesta + if self.sql_engine_type is SqlEngine.TRINO: # mptrino does implicitly cast datetime to timesta return "varchar" return self._sql_query_plan_renderer.expr_renderer.timestamp_data_type else: From e85750057269ed964453574ad2d9e76b26826545 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sun, 8 Oct 2023 01:19:25 -0600 Subject: [PATCH 03/18] Handle timestamp literals for range operator --- metricflow/sql/render/trino.py | 58 ++++++++++++++----- .../test/fixtures/sql_client_fixtures.py | 9 --- .../sql_clients/adapter_backed_ddl_client.py | 12 ++-- .../integration/test_cases/itest_simple.yaml | 2 +- .../test_cases/itest_simple_non_sm.yaml | 2 +- pyproject.toml | 4 +- 6 files changed, 53 insertions(+), 34 deletions(-) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 349c0bfa8f..834386c3de 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -5,6 +5,7 @@ from dbt_semantic_interfaces.enum_extension import assert_values_exhausted from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity from typing_extensions import override +from dateutil.parser import parse from metricflow.sql.render.expr_renderer import ( DefaultSqlExpressionRenderer, @@ -19,6 +20,9 @@ SqlPercentileExpression, SqlPercentileFunctionType, SqlTimeDeltaExpression, + SqlStringExpression, + SqlBetweenExpression, + SqlExtractExpression ) @@ -32,20 +36,20 @@ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctio SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS, } - @override - def visit_cast_to_timestamp_expr(self, node: SqlCastToTimestampExpression) -> SqlExpressionRenderResult: - """Casts the time value expression to timestamp. - - Trino's TIMESTAMP type requires timezone inputs to convert to and from different formats, whereas its - DATETIME data type does not. This is different from Databricks, which simply returns and renders inUTC by - default, or Snowflake which does something user-configurable but defaults to TIMESTAMP_NTZ, or PostgreSQL, - which adheres to the SQL standard of TIMESTAMP_NTZ. - """ - arg_rendered = self.render_sql_expr(node.arg) - return SqlExpressionRenderResult( - sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type})", - bind_parameters=arg_rendered.bind_parameters, - ) + # @override + # def visit_cast_to_timestamp_expr(self, node: SqlCastToTimestampExpression) -> SqlExpressionRenderResult: + # """Casts the time value expression to timestamp. + # + # Trino's TIMESTAMP type requires timezone inputs to convert to and from different formats, whereas its + # DATETIME data type does not. This is different from Databricks, which simply returns and renders inUTC by + # default, or Snowflake which does something user-configurable but defaults to TIMESTAMP_NTZ, or PostgreSQL, + # which adheres to the SQL standard of TIMESTAMP_NTZ. + # """ + # arg_rendered = self.render_sql_expr(node.arg) + # return SqlExpressionRenderResult( + # sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type})", + # bind_parameters=arg_rendered.bind_parameters, + # ) @override def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult: @@ -53,7 +57,7 @@ def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRe arg_rendered = node.arg.accept(self) if node.grain_to_date: return SqlExpressionRenderResult( - sql=f"DATE_TRUNC('{node.granularity.value}', {arg_rendered.sql}::timestamp)", + sql=f"DATE_TRUNC('{node.granularity.value}', TIMESTAMP {arg_rendered.sql})", bind_parameters=arg_rendered.bind_parameters, ) @@ -63,8 +67,9 @@ def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRe granularity = TimeGranularity.MONTH count *= 3 + # Trino interval needs to be in quotes. return SqlExpressionRenderResult( - sql=f"{arg_rendered.sql} - INTERVAL {count} {granularity.value}", + sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type}) - INTERVAL '{count}' {granularity.value}", bind_parameters=arg_rendered.bind_parameters, ) @@ -104,6 +109,27 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR bind_parameters=params, ) + @override + def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderResult: # noqa: D + rendered_column_arg = self.render_sql_expr(node.column_arg) + rendered_start_expr = self.render_sql_expr(node.start_expr) + rendered_end_expr = self.render_sql_expr(node.end_expr) + + bind_parameters = SqlBindParameters() + bind_parameters = bind_parameters.combine(rendered_column_arg.bind_parameters) + bind_parameters = bind_parameters.combine(rendered_start_expr.bind_parameters) + + # Handle timestamp literals differently. + if parse(rendered_start_expr.sql): + sql = f"{rendered_column_arg.sql} BETWEEN timestamp {rendered_start_expr.sql} AND timestamp {rendered_end_expr.sql}" + else: + sql = f"{rendered_column_arg.sql} BETWEEN {rendered_start_expr.sql} AND {rendered_end_expr.sql}" + + return SqlExpressionRenderResult( + sql=sql, + bind_parameters=bind_parameters, + ) + class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer): """Plan renderer for the Trino engine.""" diff --git a/metricflow/test/fixtures/sql_client_fixtures.py b/metricflow/test/fixtures/sql_client_fixtures.py index 6295484379..7ab950bf9e 100644 --- a/metricflow/test/fixtures/sql_client_fixtures.py +++ b/metricflow/test/fixtures/sql_client_fixtures.py @@ -124,15 +124,6 @@ def __configure_databricks_env_from_url(url: str, password: str, schema: str) -> __configure_test_env_from_url(url_pieces[0], password=password, schema=schema) -def __configure_trino_env_from_url(url: str, password: str, schema: str) -> None: - """Databricks has a custom http path attribute, which we have encoded into a SqlAlchemy-like URL appendage. - - This custom parsing was ported from our original client implementation for backwards compatibility with the - existing CI job configurations. - """ - pass - - def __initialize_dbt() -> None: """Invoke the dbt runner from the appropriate directory so we can fetch the relevant adapter. diff --git a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py index 55b09819a7..b0e99535fb 100644 --- a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py +++ b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py @@ -39,6 +39,7 @@ def create_table_from_dataframe( # This mirrors the SQLAlchemy schema detection logic in pandas.io.sql df = df.convert_dtypes() columns = df.columns + columns_to_insert = [] for i in range(len(df.columns)): # Format as "column_name column_type" @@ -63,7 +64,12 @@ def create_table_from_dataframe( elif type(cell) in [str, pd.Timestamp]: # Wrap cell in quotes & escape existing single quotes escaped_cell = self._quote_escape_value(str(cell)) - cells.append(f"'{escaped_cell}'") + # Trino requires timestamp literals to be wrapped in a timestamp() function. + # There is probably a better way to handle this. + if self.sql_engine_type is SqlEngine.TRINO and type(cell) is pd.Timestamp: + cells.append(f"timestamp '{escaped_cell}'") + else: + cells.append(f"'{escaped_cell}'") else: cells.append(str(cell)) @@ -94,7 +100,7 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str: if self.sql_engine_type is SqlEngine.DATABRICKS or self.sql_engine_type is SqlEngine.BIGQUERY: return "string" if self.sql_engine_type is SqlEngine.TRINO: - return "varchar(100)" + return "varchar" return "text" elif dtype == "boolean" or dtype == "bool": return "boolean" @@ -103,8 +109,6 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str: elif dtype == "float64": return self._sql_query_plan_renderer.expr_renderer.double_data_type elif dtype == "datetime64[ns]": - if self.sql_engine_type is SqlEngine.TRINO: # mptrino does implicitly cast datetime to timesta - return "varchar" return self._sql_query_plan_renderer.expr_renderer.timestamp_data_type else: raise ValueError(f"Encountered unexpected Pandas dtype ({dtype})!") diff --git a/metricflow/test/integration/test_cases/itest_simple.yaml b/metricflow/test/integration/test_cases/itest_simple.yaml index e4dc5cb5d6..96dd48a71b 100644 --- a/metricflow/test/integration/test_cases/itest_simple.yaml +++ b/metricflow/test/integration/test_cases/itest_simple.yaml @@ -42,7 +42,7 @@ integration_test: SUM(booking_value) AS booking_value , ds AS metric_time__day FROM {{ source_schema }}.fct_bookings - WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }} + WHERE {{ render_between_time_constraint("ds", "2020-01-01", "2020-01-01") }} GROUP BY ds --- diff --git a/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml b/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml index 8096844835..5f17dccd5e 100644 --- a/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml +++ b/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml @@ -15,7 +15,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings_dt b LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l ON b.listing_id = l.listing_id - WHERE {{ render_time_constraint("dt", "2020-01-01", "2020-01-01") }} + WHERE {{ render_between_time_constraint("dt", "2020-01-01", "2020-01-01") }} GROUP BY b.is_instant , b.dt diff --git a/pyproject.toml b/pyproject.toml index 34de456794..64ac05f31d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,8 +73,6 @@ sql-client-packages = [ "sqlalchemy2-stubs~=0.0.2a21", ] trino-sql-client-packages = [ - "SQLAlchemy~=1.4.42", - "sqlalchemy2-stubs~=0.0.2a21", "trino~=0.327.0", ] @@ -192,7 +190,7 @@ features = [ [tool.hatch.envs.trino-env.env-vars] MF_TEST_ADAPTER_TYPE="trino" - MF_SQL_ENGINE_URL="trino://trino@localhost:8080/memory" + MF_SQL_ENGINE_URL="trino://trino@localhost:8080/" [tool.hatch.envs.trino-env] description = "Dev environment for working with the Trino adapter" From 16feb86b6d07dacafd2848427f49d6a14eafbdb7 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sun, 8 Oct 2023 11:17:36 -0600 Subject: [PATCH 04/18] Update test cases to handle group by for Trino in metrics calculation --- metricflow/sql/render/trino.py | 20 +---------- .../test_cases/itest_constraints.yaml | 4 +-- .../integration/test_cases/itest_metrics.yaml | 36 +++++++++---------- .../test/integration/test_configured_cases.py | 18 +++++++++- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 834386c3de..00163828f6 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -15,14 +15,11 @@ from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer from metricflow.sql.sql_bind_parameters import SqlBindParameters from metricflow.sql.sql_exprs import ( - SqlCastToTimestampExpression, SqlGenerateUuidExpression, SqlPercentileExpression, SqlPercentileFunctionType, SqlTimeDeltaExpression, - SqlStringExpression, - SqlBetweenExpression, - SqlExtractExpression + SqlBetweenExpression ) @@ -36,21 +33,6 @@ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctio SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS, } - # @override - # def visit_cast_to_timestamp_expr(self, node: SqlCastToTimestampExpression) -> SqlExpressionRenderResult: - # """Casts the time value expression to timestamp. - # - # Trino's TIMESTAMP type requires timezone inputs to convert to and from different formats, whereas its - # DATETIME data type does not. This is different from Databricks, which simply returns and renders inUTC by - # default, or Snowflake which does something user-configurable but defaults to TIMESTAMP_NTZ, or PostgreSQL, - # which adheres to the SQL standard of TIMESTAMP_NTZ. - # """ - # arg_rendered = self.render_sql_expr(node.arg) - # return SqlExpressionRenderResult( - # sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type})", - # bind_parameters=arg_rendered.bind_parameters, - # ) - @override def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult: """Render time delta expression for Trino, which requires slightly different syntax from other engines.""" diff --git a/metricflow/test/integration/test_cases/itest_constraints.yaml b/metricflow/test/integration/test_cases/itest_constraints.yaml index 925c4e8db6..e641a32211 100644 --- a/metricflow/test/integration/test_cases/itest_constraints.yaml +++ b/metricflow/test/integration/test_cases/itest_constraints.yaml @@ -56,7 +56,7 @@ integration_test: SELECT SUM(booking_value) AS booking_value , ds AS metric_time__day FROM {{ source_schema }}.fct_bookings b - WHERE ds = '2020-01-01' + WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }} GROUP BY ds --- @@ -73,7 +73,7 @@ integration_test: , ds AS metric_time__day FROM {{ source_schema }}.fct_bookings b WHERE is_instant - and ds = '2020-01-01' + and {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }} GROUP BY ds --- integration_test: diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index 2625e9b0c7..89c3b9d33e 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -489,7 +489,7 @@ integration_test: group_bys: ["metric_time"] check_query: | SELECT - (bookings - ref_bookings) / CAST(bookings AS {{ double_data_type_name }}) AS non_referred_bookings_pct + (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct , metric_time__day FROM ( SELECT @@ -688,7 +688,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) a FULL OUTER JOIN ( SELECT @@ -701,7 +701,7 @@ integration_test: , SUM(1) AS bookings_2_weeks_ago FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) d ON {{ render_date_sub("C", "ds", 14, TimeGranularity.DAY) }} = d.metric_time__day ) b @@ -723,7 +723,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) a FULL OUTER JOIN ( SELECT @@ -736,7 +736,7 @@ integration_test: , SUM(1) AS bookings_at_start_of_month FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) d ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day ) b @@ -763,7 +763,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) f ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day ) a @@ -778,7 +778,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) d ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day ) b @@ -801,7 +801,7 @@ integration_test: , SUM(1) AS bookings_5_day_lag FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__day + ds ) b ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day --- @@ -889,7 +889,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings ) b ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day - GROUP BY metric_time__month + GROUP BY {{ render_date_trunc("a.ds", TimeGranularity.MONTH) }} --- integration_test: name: derived_metric_with_offset_to_grain_and_granularity @@ -906,7 +906,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings - GROUP BY metric_time__week + GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }} ) a FULL OUTER JOIN ( SELECT @@ -921,7 +921,7 @@ integration_test: ) d ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day WHERE {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} = c.ds - GROUP BY metric_time__week + GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} ) b ON a.metric_time__week = b.metric_time__week --- @@ -949,7 +949,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings ) f ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day - GROUP BY metric_time__year + GROUP BY {{ render_date_trunc("g.ds", TimeGranularity.YEAR) }} ) a FULL OUTER JOIN ( SELECT @@ -964,7 +964,7 @@ integration_test: ) d ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day WHERE {{ render_date_trunc("c.ds", TimeGranularity.YEAR) }} = c.ds - GROUP BY metric_time__year + GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.YEAR) }} ) b ON a.metric_time__year = b.metric_time__year --- @@ -987,7 +987,7 @@ integration_test: FROM {{ mf_time_spine_source }} a INNER JOIN {{ source_schema }}.fct_bookings b ON (b.ds <= a.ds) AND (b.ds > {{ render_date_sub("a", "ds", 2, TimeGranularity.DAY) }}) - GROUP BY metric_time__day + GROUP BY a.ds ) c ON {{ render_date_sub("d", "ds", 2, TimeGranularity.DAY) }} = c.metric_time__day --- @@ -1010,7 +1010,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings ) b ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day - GROUP BY metric_time__month, metric_time__week + GROUP BY {{ render_date_trunc("a.ds", TimeGranularity.MONTH) }}, {{ render_date_trunc("a.ds", TimeGranularity.WEEK) }} --- integration_test: name: derived_metric_with_offset_to_grain_and_multiple_granularities @@ -1029,7 +1029,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings - GROUP BY metric_time__week, metric_time__month + GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }}, {{ render_date_trunc("ds", TimeGranularity.MONTH) }} ) a FULL OUTER JOIN ( SELECT @@ -1046,7 +1046,7 @@ integration_test: ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day WHERE {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} = c.ds OR {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = c.ds - GROUP BY metric_time__week, metric_time__month + GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }}, {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} ) b ON a.metric_time__week = b.metric_time__week AND a.metric_time__month = b.metric_time__month @@ -1120,7 +1120,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings ) b ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day - GROUP BY metric_time__extract_month + GROUP BY {{ render_extract("a.ds", DatePart.MONTH) }} --- integration_test: name: simple_distinct_query_with_date_part diff --git a/metricflow/test/integration/test_configured_cases.py b/metricflow/test/integration/test_configured_cases.py index b8a8420df2..6acbc0b10c 100644 --- a/metricflow/test/integration/test_configured_cases.py +++ b/metricflow/test/integration/test_configured_cases.py @@ -67,8 +67,22 @@ def render_time_constraint( stop_time_plus_one_day = ( datetime.datetime.strptime(stop_time, time_format) + datetime.timedelta(days=1) ).strftime(time_format) + stop_expr = self.cast_to_ts(f"{stop_time_plus_one_day}") - return f"{expr} >= {start_expr} AND {expr} < {stop_expr}" + return f"{self.cast_expr_to_ts(expr)} >= {start_expr} AND {self.cast_expr_to_ts(expr)} < {stop_expr}" + + def render_between_time_constraint( + self, + expr: str, + start_time: str, + stop_time: str, + ) -> str: + """ Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'" + since Trino require timestamp literals to be wrapped in a timestamp() function. + """ + start_expr = self.cast_to_ts(f"{start_time}") + stop_expr = self.cast_to_ts(f"{stop_time}") + return f"{expr} BETWEEN {start_expr} AND {stop_expr}" def cast_expr_to_ts(self, expr: str) -> str: """Returns the expression as a new expression cast to the timestamp type, if applicable for the DB.""" @@ -290,6 +304,7 @@ def test_case( ).render( source_schema=mf_test_session_state.mf_source_schema, render_time_constraint=check_query_helpers.render_time_constraint, + render_between_time_constraint=check_query_helpers.render_between_time_constraint, TimeGranularity=TimeGranularity, DatePart=DatePart, render_date_sub=check_query_helpers.render_date_sub, @@ -318,6 +333,7 @@ def test_case( ).render( source_schema=mf_test_session_state.mf_source_schema, render_time_constraint=check_query_helpers.render_time_constraint, + render_between_time_constraint=check_query_helpers.render_between_time_constraint, TimeGranularity=TimeGranularity, DatePart=DatePart, render_date_sub=check_query_helpers.render_date_sub, From 72e9112cbd86f7e9bdc93115ac9c9ff24359bad4 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sun, 8 Oct 2023 19:53:15 -0600 Subject: [PATCH 05/18] Handle dry run and approx percentile for Trino along with more explicit castings Rebase on b6361 --- .../dbt_connectors/adapter_backed_client.py | 13 +++++++++- metricflow/sql/render/trino.py | 6 ++--- metricflow/test/generate_snapshots.py | 10 +++++++ .../test_cases/itest_granularity.yaml | 26 +++++++++---------- .../test_cases/itest_order_limit.yaml | 2 +- .../integration/test_cases/itest_scd.yaml | 22 ++++++++-------- .../itest_semi_additive_measure.yaml | 12 ++++----- .../test/integration/test_configured_cases.py | 6 ++--- .../test_constrain_time_range_node__plan0.sql | 2 +- ...train_time_range_node__plan0_optimized.sql | 2 +- ..._no_window_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 2 +- ...ive_metric_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 2 +- ...rived_metric_with_offset_window__plan0.sql | 2 +- ...ic_with_offset_window__plan0_optimized.sql | 2 +- ...h_offset_window_and_granularity__plan0.sql | 2 +- ...indow_and_granularity__plan0_optimized.sql | 2 +- ...fset_window_and_offset_to_grain__plan0.sql | 2 +- ...w_and_offset_to_grain__plan0_optimized.sql | 2 +- ...offset_to_grain_and_granularity__plan0.sql | 2 +- ...grain_and_granularity__plan0_optimized.sql | 2 +- ...erived_offset_cumulative_metric__plan0.sql | 4 +-- ...set_cumulative_metric__plan0_optimized.sql | 4 +-- ...et_metric_with_one_input_metric__plan0.sql | 2 +- ...with_one_input_metric__plan0_optimized.sql | 2 +- ...spine_node_with_offset_to_grain__plan0.sql | 2 +- ..._with_offset_to_grain__plan0_optimized.sql | 2 +- ...e_spine_node_with_offset_window__plan0.sql | 4 +-- ...de_with_offset_window__plan0_optimized.sql | 4 +-- ..._time_spine_node_without_offset__plan0.sql | 2 +- ...e_node_without_offset__plan0_optimized.sql | 2 +- ..._multiple_metrics_no_dimensions__plan0.sql | 4 +-- ...metrics_no_dimensions__plan0_optimized.sql | 4 +-- ...st_offset_window_with_date_part__plan0.sql | 2 +- ...window_with_date_part__plan0_optimized.sql | 2 +- ...mate_continuous_percentile_expr__plan0.sql | 2 +- 37 files changed, 94 insertions(+), 73 deletions(-) diff --git a/metricflow/cli/dbt_connectors/adapter_backed_client.py b/metricflow/cli/dbt_connectors/adapter_backed_client.py index c9c6fe7b05..cc15d521a9 100644 --- a/metricflow/cli/dbt_connectors/adapter_backed_client.py +++ b/metricflow/cli/dbt_connectors/adapter_backed_client.py @@ -219,7 +219,18 @@ def dry_run( request_id = SqlRequestId(f"mf_rid__{random_id()}") connection_name = f"MetricFlow_dry_run_request_{request_id}" # TODO - consolidate to self._adapter.validate_sql() when all implementations will work from within MetricFlow - if self.sql_engine_type is SqlEngine.BIGQUERY: + + # Trino has a bug where explain command actually creates table. Wrapping with validate to avoid this. + # See https://github.com/trinodb/trino/issues/130 + if self.sql_engine_type is SqlEngine.TRINO: + with self._adapter.connection_named(connection_name): + # Either the response will be bool value or a string with error message from Trino. + result = self._adapter.execute(f"EXPLAIN (type validate) {stmt}", auto_begin=True, fetch=True) + has_error = False if str(result[0]) == "SUCCESS" else True + if has_error: + raise DbtDatabaseError("Encountered error in Trino dry run.") + + elif self.sql_engine_type is SqlEngine.BIGQUERY: with self._adapter.connection_named(connection_name): self._adapter.validate_sql(stmt) else: diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 00163828f6..c24ff8c3df 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -2,10 +2,10 @@ from typing import Collection +from dateutil.parser import parse from dbt_semantic_interfaces.enum_extension import assert_values_exhausted from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity from typing_extensions import override -from dateutil.parser import parse from metricflow.sql.render.expr_renderer import ( DefaultSqlExpressionRenderer, @@ -15,11 +15,11 @@ from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer from metricflow.sql.sql_bind_parameters import SqlBindParameters from metricflow.sql.sql_exprs import ( + SqlBetweenExpression, SqlGenerateUuidExpression, SqlPercentileExpression, SqlPercentileFunctionType, SqlTimeDeltaExpression, - SqlBetweenExpression ) @@ -75,7 +75,7 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR function_str = "PERCENTILE_DISC" elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS: return SqlExpressionRenderResult( - sql=f"approx_quantile({arg_rendered.sql}, {percentile})", + sql=f"approx_percentile({arg_rendered.sql}, {percentile})", bind_parameters=params, ) elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_DISCRETE: diff --git a/metricflow/test/generate_snapshots.py b/metricflow/test/generate_snapshots.py index 3be91cb750..38eb97d3d7 100644 --- a/metricflow/test/generate_snapshots.py +++ b/metricflow/test/generate_snapshots.py @@ -28,6 +28,10 @@ "engine_url": postgres://...", "engine_password": "..." }, + "trino": { + "engine_url": trino://...", + "engine_password": "..." + }, } EOF ) @@ -69,6 +73,7 @@ class MetricFlowTestCredentialSetForAllEngines(FrozenBaseModel): # noqa: D big_query: MetricFlowTestCredentialSet databricks: MetricFlowTestCredentialSet postgres: MetricFlowTestCredentialSet + trino: MetricFlowTestCredentialSet @property def as_configurations(self) -> Sequence[MetricFlowTestConfiguration]: # noqa: D @@ -97,6 +102,10 @@ def as_configurations(self) -> Sequence[MetricFlowTestConfiguration]: # noqa: D engine=SqlEngine.POSTGRES, credential_set=self.postgres, ), + MetricFlowTestConfiguration( + engine=SqlEngine.TRINO, + credential_set=self.trino, + ), ) @@ -137,6 +146,7 @@ def run_tests(test_configuration: MetricFlowTestConfiguration) -> None: # noqa: or test_configuration.engine is SqlEngine.BIGQUERY or test_configuration.engine is SqlEngine.DATABRICKS or test_configuration.engine is SqlEngine.POSTGRES + or test_configuration.engine is SqlEngine.TRINO ): engine_name = test_configuration.engine.value.lower() os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name diff --git a/metricflow/test/integration/test_cases/itest_granularity.yaml b/metricflow/test/integration/test_cases/itest_granularity.yaml index 7aee578af1..ea3f974516 100644 --- a/metricflow/test/integration/test_cases/itest_granularity.yaml +++ b/metricflow/test/integration/test_cases/itest_granularity.yaml @@ -25,7 +25,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__week + {{ render_date_trunc("ds", TimeGranularity.WEEK) }} --- integration_test: name: query_granularity_for_sum_month @@ -39,7 +39,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__month + {{ render_date_trunc("ds", TimeGranularity.MONTH) }} --- integration_test: name: query_granularity_for_sum_quarter @@ -53,7 +53,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} AS metric_time__quarter FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__quarter + {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} --- integration_test: name: query_granularity_for_sum_year @@ -67,7 +67,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.YEAR) }} AS metric_time__year FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__year + {{ render_date_trunc("ds", TimeGranularity.YEAR) }} --- integration_test: name: query_granularity_for_count_distinct_day @@ -95,7 +95,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__week + {{ render_date_trunc("ds", TimeGranularity.WEEK) }} --- integration_test: name: query_granularity_for_count_distinct_month @@ -109,7 +109,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__month + {{ render_date_trunc("ds", TimeGranularity.MONTH) }} --- integration_test: name: query_granularity_for_count_distinct_quarter @@ -123,7 +123,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} AS metric_time__quarter FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__quarter + {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} --- integration_test: name: query_granularity_for_count_distinct_year @@ -137,7 +137,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.YEAR) }} AS metric_time__year FROM {{ source_schema }}.fct_bookings_extended GROUP BY - metric_time__year + {{ render_date_trunc("ds", TimeGranularity.YEAR) }} --- integration_test: name: query_granularity_for_joined_dundered_dimension_day @@ -185,7 +185,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings_extended_monthly WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-02-29") }} GROUP BY - metric_time__month + ds --- integration_test: name: metric_with_non_day_granularity_on_non_boundaries @@ -201,7 +201,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings_extended_monthly WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-02-29") }} GROUP BY - metric_time__month + ds --- integration_test: name: weekly_metric_on_non_boundaries @@ -217,7 +217,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings_extended WHERE {{ render_time_constraint("ds", "2020-01-13", "2020-01-26") }} GROUP BY - metric_time__week + {{ render_date_trunc("ds", TimeGranularity.WEEK) }} --- integration_test: name: daily_metric_with_monthly_time_dimension @@ -233,7 +233,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings_extended WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-31") }} GROUP BY - metric_time__month + {{ render_date_trunc("ds", TimeGranularity.MONTH) }} --- integration_test: name: metrics_with_different_time_granularities @@ -273,7 +273,7 @@ integration_test: ON a.ds = b.ds ) c GROUP BY - metric_time__month + ds --- integration_test: name: metrics_with_different_time_granularities_and_no_metric_time diff --git a/metricflow/test/integration/test_cases/itest_order_limit.yaml b/metricflow/test/integration/test_cases/itest_order_limit.yaml index b8a1f6b44d..7e5af9779c 100644 --- a/metricflow/test/integration/test_cases/itest_order_limit.yaml +++ b/metricflow/test/integration/test_cases/itest_order_limit.yaml @@ -69,6 +69,6 @@ integration_test: , SUM(booking_value) AS booking_value FROM {{ source_schema }}.fct_bookings GROUP BY - metric_time__month + {{ render_date_trunc("ds", TimeGranularity.MONTH) }} ORDER BY metric_time__month DESC, booking_value diff --git a/metricflow/test/integration/test_cases/itest_scd.yaml b/metricflow/test/integration/test_cases/itest_scd.yaml index 42e3d5a980..b44b444060 100644 --- a/metricflow/test/integration/test_cases/itest_scd.yaml +++ b/metricflow/test/integration/test_cases/itest_scd.yaml @@ -15,7 +15,7 @@ integration_test: ON a.listing_id = b.listing_id AND a.ds >= b.active_from AND (a.ds < b.active_to OR b.active_to is NULL) GROUP BY - listing__capacity, metric_time__day + capacity, ds --- integration_test: name: basic_scd_constrained_metric @@ -35,7 +35,7 @@ integration_test: WHERE b.capacity >= 3 GROUP BY is_instant - , metric_time__day + , ds --- integration_test: name: scd_constrained_metric_with_nulls @@ -61,8 +61,8 @@ integration_test: WHERE b.is_lux OR b.is_lux IS NULL GROUP BY is_instant - , metric_time__day - , listing__is_lux + , ds + , is_lux --- integration_test: name: scd_grouped_metric_with_second_dim @@ -87,9 +87,9 @@ integration_test: LEFT OUTER JOIN {{ source_schema }}.dim_users_latest c ON b.user_id = c.user_id GROUP BY - metric_time__day - , listing__is_lux - , listing__user__home_state_latest + a.ds + , b.is_lux + , c.home_state_latest --- integration_test: name: scd_multi_hop_groupby_through_scd @@ -112,8 +112,8 @@ integration_test: LEFT OUTER JOIN {{ source_schema }}.dim_users_latest c ON b.user_id = c.user_id GROUP BY - metric_time__day - , listing__user__home_state_latest + a.ds + , c.home_state_latest --- integration_test: name: scd_multi_hop_groupby_to_scd @@ -136,5 +136,5 @@ integration_test: ON b.lux_listing_id = c.lux_listing_id AND a.ds >= c.valid_from AND (a.ds < c.valid_to OR c.valid_to is NULL) GROUP BY - metric_time__day - , listing__lux_listing__is_confirmed_lux + a.ds + , c.is_confirmed_lux diff --git a/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml b/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml index 9043723f43..59cb7429f3 100644 --- a/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml +++ b/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml @@ -55,7 +55,7 @@ integration_test: , MAX(ds) AS ds FROM {{ source_schema }}.fct_accounts GROUP BY - metric_time__week + {{ render_date_trunc("ds", TimeGranularity.WEEK) }} , user_id ) b ON @@ -85,7 +85,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day FROM {{ source_schema }}.fct_accounts GROUP BY - metric_time__day + {{ render_date_trunc("ds", TimeGranularity.DAY) }} ) b ON a.ds = b.ds @@ -167,7 +167,7 @@ integration_test: , {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week FROM {{ source_schema }}.fct_accounts GROUP BY - metric_time__week + {{ render_date_trunc("ds", TimeGranularity.WEEK) }} ) b ON a.ds = b.ds @@ -226,7 +226,7 @@ integration_test: model: SIMPLE_MODEL metrics: ["total_account_balance_first_day"] group_bys: ["account__account_type"] - where_filter: "{{ render_time_dimension_template('account__ds', 'day') }} >= '2020-01-03'" + where_filter: "{{ render_time_dimension_template('account__ds', 'day') }} >= {{ cast_to_ts('2020-01-03') }}" check_query: | SELECT b.account_type AS account__account_type @@ -243,7 +243,7 @@ integration_test: , account_balance AS total_account_balance_first_day FROM {{ source_schema }}.fct_accounts ) a - WHERE ds >= '2020-01-03' + WHERE ds >= {{ cast_to_ts('2020-01-03') }} ) b INNER JOIN ( SELECT @@ -253,7 +253,7 @@ integration_test: ds FROM {{ source_schema }}.fct_accounts ) c - WHERE ds >= '2020-01-03' + WHERE ds >= {{ cast_to_ts('2020-01-03') }} ) d ON b.ds = d.ds__complete diff --git a/metricflow/test/integration/test_configured_cases.py b/metricflow/test/integration/test_configured_cases.py index 6acbc0b10c..32a78f79fe 100644 --- a/metricflow/test/integration/test_configured_cases.py +++ b/metricflow/test/integration/test_configured_cases.py @@ -77,9 +77,7 @@ def render_between_time_constraint( start_time: str, stop_time: str, ) -> str: - """ Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'" - since Trino require timestamp literals to be wrapped in a timestamp() function. - """ + """Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'" since Trino require timestamp literals to be wrapped in a timestamp() function.""" start_expr = self.cast_to_ts(f"{start_time}") stop_expr = self.cast_to_ts(f"{stop_time}") return f"{expr} BETWEEN {start_expr} AND {stop_expr}" @@ -317,6 +315,7 @@ def test_case( render_entity_template=check_query_helpers.render_entity_template, render_time_dimension_template=check_query_helpers.render_time_dimension_template, generate_random_uuid=check_query_helpers.generate_random_uuid, + cast_to_ts=check_query_helpers.cast_to_ts, ) if case.where_filter else None, @@ -343,6 +342,7 @@ def test_case( mf_time_spine_source=semantic_manifest_lookup.time_spine_source.spine_table.sql, double_data_type_name=check_query_helpers.double_data_type_name, generate_random_uuid=check_query_helpers.generate_random_uuid, + cast_to_ts=check_query_helpers.cast_to_ts, ) ) # If we sort, it's effectively not checking the order whatever order that the output was would be overwritten. diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql index 5b6dd99cc4..4278be9e4c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql @@ -116,4 +116,4 @@ FROM ( ) subq_0 ) subq_1 ) subq_2 -WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' +WHERE subq_2.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql index bfc4959615..0c8b28937a 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql @@ -8,4 +8,4 @@ SELECT , ds AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 -WHERE ds BETWEEN '2020-01-01' AND '2020-01-02' +WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql index 5cba3a3202..308cae149d 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -130,7 +130,7 @@ FROM ( FROM ***************************.fct_revenue revenue_src_10006 ) subq_0 ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01' + WHERE subq_1.metric_time__day BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' ) subq_2 ) subq_3 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql index c420ef636f..697ab2fb18 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -9,6 +9,6 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS revenue_all_time FROM ***************************.fct_revenue revenue_src_10006 -WHERE created_at BETWEEN '2000-01-01' AND '2020-01-01' +WHERE created_at BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql index 414159089b..bf6c16fbc2 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql @@ -130,7 +130,7 @@ FROM ( FROM ***************************.fct_revenue revenue_src_10006 ) subq_0 ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2019-12-01' AND '2020-01-01' + WHERE subq_1.metric_time__day BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' ) subq_2 ) subq_3 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql index e3387b51e4..84588c24f3 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -9,6 +9,6 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS trailing_2_months_revenue FROM ***************************.fct_revenue revenue_src_10006 -WHERE created_at BETWEEN '2019-12-01' AND '2020-01-01' +WHERE created_at BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index 38aeec72e9..453ed49bde 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -565,7 +565,7 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + CAST(subq_7.metric_time__day AS TIMESTAMP) - INTERVAL '14' day = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql index 28b07ca0e2..b7ccecc378 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + CAST(subq_22.ds AS TIMESTAMP) - INTERVAL '14' day = subq_20.metric_time__day GROUP BY subq_22.ds ) subq_26 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 0ad6211336..ad51fb152c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -565,7 +565,7 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + CAST(subq_7.metric_time__day AS TIMESTAMP) - INTERVAL '14' day = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index db9eaf374e..2341c656f8 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + CAST(subq_22.ds AS TIMESTAMP) - INTERVAL '14' day = subq_20.metric_time__day GROUP BY DATE_TRUNC('quarter', subq_22.ds) ) subq_26 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index c987150223..57de20f8c8 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -671,7 +671,7 @@ FROM ( ) subq_8 ) subq_9 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day + CAST(subq_10.metric_time__day AS TIMESTAMP) - INTERVAL '1' month = subq_9.metric_time__day ) subq_12 ) subq_13 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index e239a53fef..bce093c2bf 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -50,7 +50,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_26 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + CAST(subq_28.ds AS TIMESTAMP) - INTERVAL '1' month = subq_26.metric_time__day GROUP BY subq_28.ds ) subq_32 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index cddee48ddb..4b9645ffb7 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -672,7 +672,7 @@ FROM ( ) subq_8 ) subq_9 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day + CAST(subq_10.metric_time__day AS TIMESTAMP) - INTERVAL '1' month = subq_9.metric_time__day ) subq_12 ) subq_13 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index f4b9c2a35c..dfa4bb2e86 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -51,7 +51,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_26 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + CAST(subq_28.ds AS TIMESTAMP) - INTERVAL '1' month = subq_26.metric_time__day GROUP BY DATE_TRUNC('year', subq_28.ds) ) subq_32 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index 94cf44278b..24d934dad9 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -447,11 +447,11 @@ FROM ( ( 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_1.metric_time__day > CAST(subq_2.metric_time__day AS TIMESTAMP) - INTERVAL '2' day ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + CAST(subq_5.metric_time__day AS TIMESTAMP) - INTERVAL '2' day = subq_4.metric_time__day ) subq_7 ) subq_8 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql index 1b96977064..2655024e11 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -24,11 +24,11 @@ FROM ( ( bookings_source_src_10001.ds <= subq_14.ds ) AND ( - bookings_source_src_10001.ds > subq_14.ds - INTERVAL 2 day + bookings_source_src_10001.ds > CAST(subq_14.ds AS TIMESTAMP) - INTERVAL '2' day ) ) subq_15 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + CAST(subq_17.ds AS TIMESTAMP) - INTERVAL '2' day = subq_15.metric_time__day GROUP BY subq_17.ds ) subq_21 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index 6b4f9e31f9..609ed03345 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -330,7 +330,7 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + CAST(subq_2.metric_time__day AS TIMESTAMP) - INTERVAL '5' day = subq_1.metric_time__day ) subq_4 ) subq_5 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index b5a8855b9c..6d4efccd71 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -21,7 +21,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_9 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + CAST(subq_11.ds AS TIMESTAMP) - INTERVAL '5' day = subq_9.metric_time__day GROUP BY subq_11.ds ) subq_15 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql index 9f23719b49..38492f6341 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql @@ -8,7 +8,7 @@ FROM ( 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' + WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql index 6a4ced8cd8..4fddfa6c2c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( SELECT ds AS metric_time__day FROM ***************************.mf_time_spine subq_13 - WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql index 406b83cae3..811955977e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -8,7 +8,7 @@ FROM ( 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' + WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions @@ -244,4 +244,4 @@ INNER JOIN ( ) subq_3 ) subq_4 ON - subq_5.metric_time__day - INTERVAL 10 day = subq_4.metric_time__day + CAST(subq_5.metric_time__day AS TIMESTAMP) - INTERVAL '10' day = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql index 4a9399b1f2..98efd224f9 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( SELECT ds AS metric_time__day FROM ***************************.mf_time_spine subq_13 - WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions @@ -33,4 +33,4 @@ INNER JOIN ( ) subq_10 ) subq_11 ON - subq_12.metric_time__day - INTERVAL 10 day = subq_11.metric_time__day + CAST(subq_12.metric_time__day AS TIMESTAMP) - INTERVAL '10' day = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql index 2093e49b0b..642ca46e74 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql @@ -8,7 +8,7 @@ FROM ( 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' + WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql index 4afadfc929..1b4288571b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( SELECT ds AS metric_time__day FROM ***************************.mf_time_spine subq_13 - WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01' ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql index 54b108dd33..275fe93c4e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql @@ -331,7 +331,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_0 ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + WHERE subq_1.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_2 ) subq_3 ) subq_4 @@ -565,7 +565,7 @@ CROSS JOIN ( FROM ***************************.dim_listings_latest listings_latest_src_10004 ) subq_6 ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_8 ) subq_9 ) subq_10 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql index 74dcbb71f8..58bfd2747e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql @@ -13,7 +13,7 @@ FROM ( SELECT SUM(1) AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 - WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' + WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_17 CROSS JOIN ( -- Read Elements From Semantic Model 'listings_latest' @@ -26,5 +26,5 @@ CROSS JOIN ( SELECT SUM(1) AS listings FROM ***************************.dim_listings_latest listings_latest_src_10004 - WHERE created_at BETWEEN '2020-01-01' AND '2020-01-01' + WHERE created_at BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_23 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index a65895e8b1..243fd36ac8 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -565,7 +565,7 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + CAST(subq_7.metric_time__day AS TIMESTAMP) - INTERVAL '14' day = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql index 5f6ec1ee79..6deb5f4a9e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + CAST(subq_22.ds AS TIMESTAMP) - INTERVAL '14' day = subq_20.metric_time__day GROUP BY EXTRACT(dow FROM subq_22.ds) ) subq_26 diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql index ca1e6ab7a9..5ad435c9e1 100644 --- a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql +++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql @@ -1,4 +1,4 @@ -- Test Approximate Continuous Percentile Expression SELECT - approx_quantile(a.col0, 0.5) AS col0_percentile + approx_percentile(a.col0, 0.5) AS col0_percentile FROM foo.bar a From bf83458f6f68c2d6480adf89bd5646aefc2fbdef Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sun, 8 Oct 2023 19:57:07 -0600 Subject: [PATCH 06/18] Add changelog --- .changes/unreleased/Features-20231008-195608.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Features-20231008-195608.yaml diff --git a/.changes/unreleased/Features-20231008-195608.yaml b/.changes/unreleased/Features-20231008-195608.yaml new file mode 100644 index 0000000000..bd16ae0233 --- /dev/null +++ b/.changes/unreleased/Features-20231008-195608.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Add Trino support to the MetricFlow. +time: 2023-10-08T19:56:08.427006-06:00 +custom: + Author: sarbmeetka + Issue: "207" From 73b71dafa2e0bd366b9ffa470c5914cc2c31a807 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 24 Oct 2023 02:11:54 -0600 Subject: [PATCH 07/18] Fix percentile function and rename sqltimedelta function in Trino client --- metricflow/sql/render/trino.py | 67 ++++++++++--------- pyproject.toml | 118 ++++++++++++++++----------------- 2 files changed, 93 insertions(+), 92 deletions(-) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index c24ff8c3df..8f0b153ca1 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -4,6 +4,7 @@ from dateutil.parser import parse from dbt_semantic_interfaces.enum_extension import assert_values_exhausted +from dbt_semantic_interfaces.type_enums.date_part import DatePart from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity from typing_extensions import override @@ -19,7 +20,7 @@ SqlGenerateUuidExpression, SqlPercentileExpression, SqlPercentileFunctionType, - SqlTimeDeltaExpression, + SqlSubtractTimeIntervalExpression, ) @@ -34,34 +35,27 @@ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctio } @override - def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult: - """Render time delta expression for Trino, which requires slightly different syntax from other engines.""" + def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpressionRenderResult: + return SqlExpressionRenderResult( + sql="uuid()", + bind_parameters=SqlBindParameters(), + ) + + @override + def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: + """Render time delta for Trino, require granularity in quotes and function name change.""" arg_rendered = node.arg.accept(self) - if node.grain_to_date: - return SqlExpressionRenderResult( - sql=f"DATE_TRUNC('{node.granularity.value}', TIMESTAMP {arg_rendered.sql})", - bind_parameters=arg_rendered.bind_parameters, - ) count = node.count granularity = node.granularity if granularity == TimeGranularity.QUARTER: granularity = TimeGranularity.MONTH count *= 3 - - # Trino interval needs to be in quotes. return SqlExpressionRenderResult( - sql=f"CAST({arg_rendered.sql} AS {self.timestamp_data_type}) - INTERVAL '{count}' {granularity.value}", + sql=f"DATE_ADD('{granularity.value}', -{count}, {arg_rendered.sql})", bind_parameters=arg_rendered.bind_parameters, ) - @override - def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpressionRenderResult: - return SqlExpressionRenderResult( - sql="uuid()", - bind_parameters=SqlBindParameters(), - ) - @override def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionRenderResult: """Render a percentile expression for Trino.""" @@ -69,30 +63,26 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR params = arg_rendered.bind_parameters percentile = node.percentile_args.percentile - if node.percentile_args.function_type is SqlPercentileFunctionType.CONTINUOUS: - function_str = "PERCENTILE_CONT" - elif node.percentile_args.function_type is SqlPercentileFunctionType.DISCRETE: - function_str = "PERCENTILE_DISC" - elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS: + if node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS: return SqlExpressionRenderResult( sql=f"approx_percentile({arg_rendered.sql}, {percentile})", bind_parameters=params, ) - elif node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_DISCRETE: + elif ( + node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_DISCRETE + or node.percentile_args.function_type is SqlPercentileFunctionType.DISCRETE + or node.percentile_args.function_type is SqlPercentileFunctionType.CONTINUOUS + ): raise RuntimeError( - "Approximate discrete percentile aggregatew not supported for Trino. Set " - + "use_discrete_percentile and/or use_approximate_percentile to false in all percentile measures." + "Discrete, Continuous and Approximate discrete percentile aggregates are not supported for Trino. Set " + + "use_approximate_percentile and disable use_discrete_percentile in all percentile measures." ) else: assert_values_exhausted(node.percentile_args.function_type) - return SqlExpressionRenderResult( - sql=f"{function_str}({percentile}) WITHIN GROUP (ORDER BY ({arg_rendered.sql}))", - bind_parameters=params, - ) - @override - def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderResult: # noqa: D + def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderResult: + """Render a between expression for Trino. If the expression is a timestamp literal then wrap literals with timestamp.""" rendered_column_arg = self.render_sql_expr(node.column_arg) rendered_start_expr = self.render_sql_expr(node.start_expr) rendered_end_expr = self.render_sql_expr(node.end_expr) @@ -100,6 +90,7 @@ def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderR bind_parameters = SqlBindParameters() bind_parameters = bind_parameters.combine(rendered_column_arg.bind_parameters) bind_parameters = bind_parameters.combine(rendered_start_expr.bind_parameters) + bind_parameters = bind_parameters.combine(rendered_end_expr.bind_parameters) # Handle timestamp literals differently. if parse(rendered_start_expr.sql): @@ -112,6 +103,16 @@ def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderR bind_parameters=bind_parameters, ) + @override + def render_date_part(self, date_part: DatePart) -> str: + """Render DATE PART for an EXTRACT expression. + Override DAY_OF_WEEK in Trino to ISO date part to ensure all engines return consistent results. + """ + if date_part is DatePart.DOW: + return "DAY_OF_WEEK" + + return date_part.value + class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer): """Plan renderer for the Trino engine.""" @@ -121,4 +122,4 @@ class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer): @property @override def expr_renderer(self) -> SqlExpressionRenderer: - return self.EXPR_RENDERER + return self.EXPR_RENDERER \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 64ac05f31d..5ad45c6689 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,14 +15,14 @@ authors = [ ] classifiers = [ - "Development Status :: 4 - Beta", - "Programming Language :: Python", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = [ "Jinja2>=2.11.3", @@ -54,26 +54,26 @@ mf = 'metricflow.cli.main:cli' [project.optional-dependencies] dev-packages = [ - "mypy~=1.7.0", - "pre-commit~=3.2.2", - # Bug with mypy: https://github.com/pallets/click/issues/2558#issuecomment-1656546003 - "click>=8.1.6", - "pytest-mock~=3.7.0", - "pytest-xdist~=3.2.1", - "pytest~=7.1.1", - "types-PyYAML", - "types-python-dateutil", - "types-tabulate", + "mypy~=1.7.0", + "pre-commit~=3.2.2", + # Bug with mypy: https://github.com/pallets/click/issues/2558#issuecomment-1656546003 + "click>=8.1.6", + "pytest-mock~=3.7.0", + "pytest-xdist~=3.2.1", + "pytest~=7.1.1", + "types-PyYAML", + "types-python-dateutil", + "types-tabulate", ] # These are currently separate for ease of removal, but due to the way Python # handles import statements they are required in all test environments sql-client-packages = [ - "SQLAlchemy~=1.4.42", - "sqlalchemy2-stubs~=0.0.2a21", + "SQLAlchemy~=1.4.42", + "sqlalchemy2-stubs~=0.0.2a21", ] trino-sql-client-packages = [ - "trino~=0.327.0", + "trino~=0.327.0", ] dbt-postgres = [ @@ -101,19 +101,19 @@ dbt-duckdb = [ ] dbt-trino = [ - "dbt-trino~=1.6.0", + "dbt-trino~=1.7.0", ] [tool.hatch.build.targets.sdist] exclude = [ - "/.github", - "/.changes", - ".changie.yaml", - ".gitignore", - ".pre-commit-config.yaml", - "CONTRIBUTING.md", - "MAKEFILE", - "/tests", + "/.github", + "/.changes", + ".changie.yaml", + ".gitignore", + ".pre-commit-config.yaml", + "CONTRIBUTING.md", + "MAKEFILE", + "/tests", ] [tool.hatch.envs.dev-env] @@ -125,79 +125,79 @@ features = [ ] [tool.hatch.envs.dev-env.env-vars] - MF_TEST_ADAPTER_TYPE="duckdb" - MF_SQL_ENGINE_URL="duckdb://" +MF_TEST_ADAPTER_TYPE="duckdb" +MF_SQL_ENGINE_URL="duckdb://" [tool.hatch.envs.postgres-env.env-vars] - MF_SQL_ENGINE_URL="postgresql://metricflow@localhost:5432/metricflow" - MF_SQL_ENGINE_PASSWORD="metricflowing" - MF_TEST_ADAPTER_TYPE="postgres" +MF_SQL_ENGINE_URL="postgresql://metricflow@localhost:5432/metricflow" +MF_SQL_ENGINE_PASSWORD="metricflowing" +MF_TEST_ADAPTER_TYPE="postgres" [tool.hatch.envs.postgres-env] description = "Dev environment for working with Postgres adapter" features = [ - "dev-packages", - "dbt-postgres", - "sql-client-packages", + "dev-packages", + "dbt-postgres", + "sql-client-packages", ] # NOTE: All of the below should have their authentication credentials # configured independently of the hatch env construction [tool.hatch.envs.bigquery-env.env-vars] - MF_TEST_ADAPTER_TYPE="bigquery" +MF_TEST_ADAPTER_TYPE="bigquery" [tool.hatch.envs.bigquery-env] description = "Dev environment for working with the BigQuery adapter" features = [ - "dev-packages", - "dbt-bigquery", - "sql-client-packages", + "dev-packages", + "dbt-bigquery", + "sql-client-packages", ] [tool.hatch.envs.databricks-env.env-vars] - MF_TEST_ADAPTER_TYPE="databricks" +MF_TEST_ADAPTER_TYPE="databricks" [tool.hatch.envs.databricks-env] description = "Dev environment for working with the Databricks adapter" features = [ - "dev-packages", - "dbt-databricks", - "sql-client-packages", + "dev-packages", + "dbt-databricks", + "sql-client-packages", ] [tool.hatch.envs.redshift-env.env-vars] - MF_TEST_ADAPTER_TYPE="redshift" +MF_TEST_ADAPTER_TYPE="redshift" [tool.hatch.envs.redshift-env] description = "Dev environment for working with the Redshift adapter" features = [ - "dev-packages", - "dbt-redshift", - "sql-client-packages", + "dev-packages", + "dbt-redshift", + "sql-client-packages", ] [tool.hatch.envs.snowflake-env.env-vars] - MF_TEST_ADAPTER_TYPE="snowflake" +MF_TEST_ADAPTER_TYPE="snowflake" [tool.hatch.envs.snowflake-env] description = "Dev environment for working with Snowflake adapter" features = [ - "dev-packages", - "dbt-snowflake", - "sql-client-packages", + "dev-packages", + "dbt-snowflake", + "sql-client-packages", ] [tool.hatch.envs.trino-env.env-vars] - MF_TEST_ADAPTER_TYPE="trino" - MF_SQL_ENGINE_URL="trino://trino@localhost:8080/" +MF_TEST_ADAPTER_TYPE="trino" +MF_SQL_ENGINE_URL="trino://trino@localhost:8080/" [tool.hatch.envs.trino-env] description = "Dev environment for working with the Trino adapter" features = [ - "dev-packages", - "dbt-trino", - "trino-sql-client-packages", + "dev-packages", + "dbt-trino", + "trino-sql-client-packages", ] [tool.black] From 1738d09559b2dd3504b8d283a287e68b1611932c Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 12:15:15 -0700 Subject: [PATCH 08/18] Handle extract for Trino --- metricflow/sql/render/trino.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 8f0b153ca1..590370a59b 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -46,6 +46,12 @@ def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlE """Render time delta for Trino, require granularity in quotes and function name change.""" arg_rendered = node.arg.accept(self) + if node.granularity: + return SqlExpressionRenderResult( + sql=f"DATE_TRUNC('{node.granularity.value}', {arg_rendered.sql})", + bind_parameters=arg_rendered.bind_parameters, + ) + count = node.count granularity = node.granularity if granularity == TimeGranularity.QUARTER: @@ -106,6 +112,7 @@ def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderR @override def render_date_part(self, date_part: DatePart) -> str: """Render DATE PART for an EXTRACT expression. + Override DAY_OF_WEEK in Trino to ISO date part to ensure all engines return consistent results. """ if date_part is DatePart.DOW: From 69bb34bb545a3beaab5f87b8b28f00b2ea92d729 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 12:32:16 -0700 Subject: [PATCH 09/18] fix lint issues --- .../populate_persistent_source_schemas.py | 1 + ...st_convert_query_semantic_model__plan0.sql | 10 +- ...le_semantic_model_with_measures__plan0.sql | 20 +- ...semantic_model_without_measures__plan0.sql | 10 +- .../Trino/test_cumulative_metric__plan0.sql | 89 ++ ...est_cumulative_metric__plan0_optimized.sql | 12 + ...cumulative_metric_grain_to_date__plan0.sql | 89 ++ ..._metric_grain_to_date__plan0_optimized.sql | 12 + .../test_cumulative_metric_no_ds__plan0.sql | 84 ++ ...mulative_metric_no_ds__plan0_optimized.sql | 9 + ...est_cumulative_metric_no_window__plan0.sql | 89 ++ ...tive_metric_no_window__plan0_optimized.sql | 12 + ..._no_window_with_time_constraint__plan0.sql | 130 +++ ..._with_time_constraint__plan0_optimized.sql | 14 + ...with_non_adjustable_time_filter__plan0.sql | 335 ++++++ ...djustable_time_filter__plan0_optimized.sql | 26 + ...ive_metric_with_time_constraint__plan0.sql | 190 ++++ ..._with_time_constraint__plan0_optimized.sql | 36 + .../Trino/test_build_metric_tasks__query0.sql | 2 +- .../test_combined_metrics_plan__ep_0.xml | 8 +- .../Trino/test_multihop_joined_plan__ep_0.xml | 72 +- .../test_compute_metrics_node__plan0.sql | 50 +- ...o_from_multiple_semantic_models__plan0.sql | 137 +-- ...tiple_semantic_models__plan0_optimized.sql | 134 ++- ...atio_from_single_semantic_model__plan0.sql | 50 +- ...ompute_metrics_node_simple_expr__plan0.sql | 50 +- .../test_constrain_time_range_node__plan0.sql | 30 +- ...train_time_range_node__plan0_optimized.sql | 6 +- .../Trino/test_filter_node__plan0.sql | 30 +- ...lter_with_where_constraint_node__plan0.sql | 30 +- ...where_constraint_node__plan0_optimized.sql | 2 +- ...spine_node_with_offset_to_grain__plan0.sql | 37 +- ..._with_offset_to_grain__plan0_optimized.sql | 4 +- ...e_spine_node_with_offset_window__plan0.sql | 39 +- ...de_with_offset_window__plan0_optimized.sql | 6 +- ..._time_spine_node_without_offset__plan0.sql | 37 +- ...e_node_without_offset__plan0_optimized.sql | 4 +- .../test_measure_aggregation_node__plan0.sql | 30 +- .../Trino/test_multi_join_node__plan0.sql | 70 +- .../Trino/test_order_by_node__plan0.sql | 30 +- .../test_order_by_node__plan0_optimized.sql | 2 +- .../test_semi_additive_join_node__plan0.sql | 22 +- ...mi_additive_join_node__plan0_optimized.sql | 14 +- ...dditive_join_node_with_grouping__plan0.sql | 22 +- ...in_node_with_grouping__plan0_optimized.sql | 14 +- ...join_node_with_queried_group_by__plan0.sql | 22 +- ...with_queried_group_by__plan0_optimized.sql | 14 +- .../Trino/test_single_join_node__plan0.sql | 50 +- .../Trino/test_source_node__plan0.sql | 30 +- .../test_source_node__plan0_optimized.sql | 30 +- .../Trino/test_derived_metric__plan0.sql | 447 ++++++++ .../test_derived_metric__plan0_optimized.sql | 53 + ...ved_metric_with_offset_to_grain__plan0.sql | 547 +++++++++ ..._with_offset_to_grain__plan0_optimized.sql | 57 + ...offset_to_grain_and_granularity__plan0.sql | 548 +++++++++ ...grain_and_granularity__plan0_optimized.sql | 58 + ...rived_metric_with_offset_window__plan0.sql | 547 +++++++++ ...ic_with_offset_window__plan0_optimized.sql | 57 + ...h_offset_window_and_granularity__plan0.sql | 547 +++++++++ ...indow_and_granularity__plan0_optimized.sql | 57 + ...fset_window_and_offset_to_grain__plan0.sql | 647 +++++++++++ ...w_and_offset_to_grain__plan0_optimized.sql | 61 + ...offset_to_grain_and_granularity__plan0.sql | 648 +++++++++++ ...grain_and_granularity__plan0_optimized.sql | 62 + ...h_offset_window_and_time_filter__plan0.sql | 561 +++++++++ ...indow_and_time_filter__plan0_optimized.sql | 66 ++ ...erived_offset_cumulative_metric__plan0.sql | 434 +++++++ ...set_cumulative_metric__plan0_optimized.sql | 34 + ...et_metric_with_one_input_metric__plan0.sql | 320 ++++++ ...with_one_input_metric__plan0_optimized.sql | 27 + .../test_nested_derived_metric__plan0.sql | 899 +++++++++++++++ ...nested_derived_metric__plan0_optimized.sql | 111 ++ .../test_cumulative_fill_nulls__plan0.sql | 342 ++++++ ...cumulative_fill_nulls__plan0_optimized.sql | 33 + ...fill_nulls_for_one_input_metric__plan0.sql | 561 +++++++++ ..._for_one_input_metric__plan0_optimized.sql | 71 ++ ...e_fill_nulls_with_0_metric_time__plan0.sql | 228 ++++ ...ls_with_0_metric_time__plan0_optimized.sql | 31 + ..._simple_fill_nulls_with_0_month__plan0.sql | 230 ++++ ...ll_nulls_with_0_month__plan0_optimized.sql | 38 + ...th_0_with_categorical_dimension__plan0.sql | 214 ++++ ...categorical_dimension__plan0_optimized.sql | 22 + ...lls_with_0_with_non_metric_time__plan0.sql | 214 ++++ ..._with_non_metric_time__plan0_optimized.sql | 22 + ...e_fill_nulls_without_time_spine__plan0.sql | 214 ++++ ...ls_without_time_spine__plan0_optimized.sql | 22 + ...st_offset_window_with_date_part__plan0.sql | 547 +++++++++ ...window_with_date_part__plan0_optimized.sql | 57 + ...est_simple_query_with_date_part__plan0.sql | 214 ++++ ..._query_with_date_part__plan0_optimized.sql | 17 + ..._query_with_multiple_date_parts__plan0.sql | 240 ++++ ...h_multiple_date_parts__plan0_optimized.sql | 38 + ...orm_node_using_non_primary_time__plan0.sql | 37 +- ...sing_non_primary_time__plan0_optimized.sql | 35 +- ...ansform_node_using_primary_time__plan0.sql | 37 +- ...de_using_primary_time__plan0_optimized.sql | 35 +- ...uery_with_metric_time_dimension__plan0.sql | 74 +- ...metric_time_dimension__plan0_optimized.sql | 6 +- .../test_common_semantic_model__plan0.sql | 441 +++++++ ...common_semantic_model__plan0_optimized.sql | 42 + .../Trino/test_distinct_values__plan0.sql | 135 +++ .../test_distinct_values__plan0_optimized.sql | 17 + ...th_where_constraint_on_join_dim__plan0.sql | 387 +++++++ ...onstraint_on_join_dim__plan0_optimized.sql | 35 + .../test_join_to_scd_dimension__plan0.sql | 317 ++++++ ...join_to_scd_dimension__plan0_optimized.sql | 47 + .../Trino/test_limit_rows__plan0.sql | 221 ++++ .../test_limit_rows__plan0_optimized.sql | 19 + ...al_dimension_using_local_entity__plan0.sql | 151 +++ ...on_using_local_entity__plan0_optimized.sql | 17 + .../Trino/test_measure_constraint__plan0.sql | 1012 +++++++++++++++++ ...st_measure_constraint__plan0_optimized.sql | 96 ++ ..._constraint_with_reused_measure__plan0.sql | 463 ++++++++ ...t_with_reused_measure__plan0_optimized.sql | 53 + ...aint_with_single_expr_and_alias__plan0.sql | 236 ++++ ...single_expr_and_alias__plan0_optimized.sql | 28 + ..._multiple_sources_no_dimensions__plan0.sql | 368 ++++++ ...sources_no_dimensions__plan0_optimized.sql | 26 + ...multi_hop_through_scd_dimension__plan0.sql | 460 ++++++++ ...through_scd_dimension__plan0_optimized.sql | 52 + ...test_multi_hop_to_scd_dimension__plan0.sql | 440 +++++++ ..._hop_to_scd_dimension__plan0_optimized.sql | 55 + .../Trino/test_multihop_node__plan0.sql | 366 ++++++ .../test_multihop_node__plan0_optimized.sql | 35 + ..._multiple_metrics_no_dimensions__plan0.sql | 538 +++++++++ ...metrics_no_dimensions__plan0_optimized.sql | 30 + .../Trino/test_partitioned_join__plan0.sql | 244 ++++ ...test_partitioned_join__plan0_optimized.sql | 29 + .../Trino/test_render_query__query0.sql | 2 +- ...st_render_write_to_table_query__query0.sql | 2 +- .../test_simple_join_to_time_spine__plan0.sql | 228 ++++ ...le_join_to_time_spine__plan0_optimized.sql | 26 + 132 files changed, 18413 insertions(+), 818 deletions(-) create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql create mode 100644 metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql create mode 100644 metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql create mode 100644 metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql create mode 100644 metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql diff --git a/metricflow/test/populate_persistent_source_schemas.py b/metricflow/test/populate_persistent_source_schemas.py index 0f0ff6f59c..a37412216b 100644 --- a/metricflow/test/populate_persistent_source_schemas.py +++ b/metricflow/test/populate_persistent_source_schemas.py @@ -29,6 +29,7 @@ def populate_schemas(test_configuration: MetricFlowTestConfiguration) -> None: or test_configuration.engine is SqlEngine.BIGQUERY or test_configuration.engine is SqlEngine.DATABRICKS or test_configuration.engine is SqlEngine.REDSHIFT + or test_configuration.engine is SqlEngine.TRINO ): engine_name = test_configuration.engine.value.lower() os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql index dab2be52a2..1807b48040 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql @@ -1,7 +1,7 @@ -- Read Elements From Semantic Model 'revenue' SELECT revenue_src_10006.revenue AS txn_revenue - , revenue_src_10006.created_at AS ds__day + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter @@ -9,11 +9,10 @@ SELECT , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , revenue_src_10006.created_at AS company__ds__day + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter @@ -21,9 +20,8 @@ SELECT , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy , revenue_src_10006.user_id AS user , revenue_src_10006.user_id AS company__user diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql index 93f9b1f47a..9836f4381d 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql @@ -1,7 +1,7 @@ -- Read Elements From Semantic Model 'id_verifications' SELECT 1 AS identity_verifications - , id_verifications_src_10003.ds AS ds__day + , DATE_TRUNC('day', id_verifications_src_10003.ds) AS ds__day , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter @@ -9,11 +9,10 @@ SELECT , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month - , EXTRACT(week FROM id_verifications_src_10003.ds) AS ds__extract_week , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day - , EXTRACT(dow FROM id_verifications_src_10003.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS ds__extract_dow , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy - , id_verifications_src_10003.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter @@ -21,12 +20,11 @@ SELECT , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy , id_verifications_src_10003.verification_type - , id_verifications_src_10003.ds AS verification__ds__day + , DATE_TRUNC('day', id_verifications_src_10003.ds) AS verification__ds__day , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter @@ -34,11 +32,10 @@ SELECT , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month - , EXTRACT(week FROM id_verifications_src_10003.ds) AS verification__ds__extract_week , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day - , EXTRACT(dow FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy - , id_verifications_src_10003.ds_partitioned AS verification__ds_partitioned__day + , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__day , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter @@ -46,9 +43,8 @@ SELECT , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month - , EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day - , EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy , id_verifications_src_10003.verification_type AS verification__verification_type , id_verifications_src_10003.verification_id AS verification diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql index 184fc0044a..35b84cedba 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql @@ -1,6 +1,6 @@ -- Read Elements From Semantic Model 'users_latest' SELECT - users_latest_src_10008.ds AS ds_latest__day + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter @@ -8,12 +8,11 @@ SELECT , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month - , EXTRACT(week FROM users_latest_src_10008.ds) AS ds_latest__extract_week , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day - , EXTRACT(dow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS ds_latest__extract_dow , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy , users_latest_src_10008.home_state_latest - , users_latest_src_10008.ds AS user__ds_latest__day + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter @@ -21,9 +20,8 @@ SELECT , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month - , EXTRACT(week FROM users_latest_src_10008.ds) AS user__ds_latest__extract_week , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day - , EXTRACT(dow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy , users_latest_src_10008.home_state_latest AS user__home_state_latest , users_latest_src_10008.user_id AS user diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql new file mode 100644 index 0000000000..a19fbc0ed7 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql @@ -0,0 +1,89 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql new file mode 100644 index 0000000000..6596468bca --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS trailing_2_months_revenue +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql new file mode 100644 index 0000000000..689c32ba68 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql @@ -0,0 +1,89 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS revenue_mtd +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql new file mode 100644 index 0000000000..06853be07e --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_mtd +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql new file mode 100644 index 0000000000..5d6708585a --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql @@ -0,0 +1,84 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue'] + SELECT + subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 +) subq_3 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql new file mode 100644 index 0000000000..ba2c45a4ca --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql @@ -0,0 +1,9 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(revenue) AS trailing_2_months_revenue +FROM ***************************.fct_revenue revenue_src_10006 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql new file mode 100644 index 0000000000..291d6de321 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql @@ -0,0 +1,89 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.ds__month + , subq_3.txn_revenue AS revenue_all_time +FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__month + , SUM(subq_2.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_1.ds__month + , subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__month +) subq_3 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql new file mode 100644 index 0000000000..220fb6083c --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql @@ -0,0 +1,12 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_all_time +FROM ***************************.fct_revenue revenue_src_10006 +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..9c6155e377 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -0,0 +1,130 @@ +-- Compute Metrics via Expressions +SELECT + subq_4.ds__month + , subq_4.txn_revenue AS revenue_all_time +FROM ( + -- Aggregate Measures + SELECT + subq_3.ds__month + , SUM(subq_3.txn_revenue) AS txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'ds__month'] + SELECT + subq_2.ds__month + , subq_2.txn_revenue + FROM ( + -- 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.company__ds__day + , subq_1.company__ds__week + , subq_1.company__ds__month + , subq_1.company__ds__quarter + , subq_1.company__ds__year + , subq_1.company__ds__extract_year + , subq_1.company__ds__extract_quarter + , subq_1.company__ds__extract_month + , subq_1.company__ds__extract_day + , subq_1.company__ds__extract_dow + , subq_1.company__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.company__user + , subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' + ) subq_2 + ) subq_3 + GROUP BY + subq_3.ds__month +) subq_4 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..c8d6cd46c9 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Read Elements From Semantic Model 'revenue' +-- Metric Time Dimension 'ds' +-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00] +-- Pass Only Elements: +-- ['txn_revenue', 'ds__month'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + DATE_TRUNC('month', created_at) AS ds__month + , SUM(revenue) AS revenue_all_time +FROM ***************************.fct_revenue revenue_src_10006 +WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' +GROUP BY + DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql new file mode 100644 index 0000000000..19ade80c3b --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql @@ -0,0 +1,335 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.bookers AS every_two_days_bookers +FROM ( + -- Aggregate Measures + SELECT + subq_6.metric_time__day + , COUNT(DISTINCT subq_6.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.bookers + FROM ( + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + ) + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' + ) subq_6 + GROUP BY + subq_6.metric_time__day +) subq_7 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql new file mode 100644 index 0000000000..c71bac4a78 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Constrain Output with WHERE +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__day + , COUNT(DISTINCT bookers) AS every_two_days_bookers +FROM ( + -- Join Self Over Time Range + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_11.ds AS metric_time__day + , bookings_source_src_10001.guest_id AS bookers + FROM ***************************.mf_time_spine subq_11 + INNER JOIN + ***************************.fct_bookings bookings_source_src_10001 + ON + ( + DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_11.ds + ) AND ( + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_11.ds) + ) +) subq_13 +WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..bbb92b55c8 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql @@ -0,0 +1,190 @@ +-- Compute Metrics via Expressions +SELECT + subq_8.metric_time__month + , subq_8.txn_revenue AS trailing_2_months_revenue +FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.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__month + , subq_6.txn_revenue + FROM ( + -- Pass Only Elements: + -- ['txn_revenue', 'metric_time__month'] + SELECT + subq_5.metric_time__month + , subq_5.txn_revenue + FROM ( + -- Join Self Over Time Range + 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.company__ds__day AS company__ds__day + , subq_2.company__ds__week AS company__ds__week + , subq_2.company__ds__month AS company__ds__month + , subq_2.company__ds__quarter AS company__ds__quarter + , subq_2.company__ds__year AS company__ds__year + , subq_2.company__ds__extract_year AS company__ds__extract_year + , subq_2.company__ds__extract_quarter AS company__ds__extract_quarter + , subq_2.company__ds__extract_month AS company__ds__extract_month + , subq_2.company__ds__extract_day AS company__ds__extract_day + , subq_2.company__ds__extract_dow AS company__ds__extract_dow + , subq_2.company__ds__extract_doy AS company__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.company__user AS company__user + , subq_2.txn_revenue AS txn_revenue + FROM ( + -- Date Spine + SELECT + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + WHERE subq_4.ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' + ) subq_3 + INNER JOIN ( + -- Constrain Time Range to [2019-12-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.company__ds__day + , subq_1.company__ds__week + , subq_1.company__ds__month + , subq_1.company__ds__quarter + , subq_1.company__ds__year + , subq_1.company__ds__extract_year + , subq_1.company__ds__extract_quarter + , subq_1.company__ds__extract_month + , subq_1.company__ds__extract_day + , subq_1.company__ds__extract_dow + , subq_1.company__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.company__user + , subq_1.txn_revenue + 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.company__ds__day + , subq_0.company__ds__week + , subq_0.company__ds__month + , subq_0.company__ds__quarter + , subq_0.company__ds__year + , subq_0.company__ds__extract_year + , subq_0.company__ds__extract_quarter + , subq_0.company__ds__extract_month + , subq_0.company__ds__extract_day + , subq_0.company__ds__extract_dow + , subq_0.company__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.company__user + , subq_0.txn_revenue + FROM ( + -- Read Elements From Semantic Model 'revenue' + SELECT + revenue_src_10006.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy + , revenue_src_10006.user_id AS user + , revenue_src_10006.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10006 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' + ) subq_2 + ON + ( + subq_2.metric_time__day <= subq_3.metric_time__day + ) AND ( + subq_2.metric_time__day > DATE_TRUNC('month', subq_3.metric_time__day) + ) + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__month BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' + ) subq_7 + GROUP BY + subq_7.metric_time__month +) subq_8 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..e89c6158e9 --- /dev/null +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Join Self Over Time Range +-- Pass Only Elements: +-- ['txn_revenue', 'metric_time__month'] +-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + subq_11.metric_time__month AS metric_time__month + , SUM(subq_11.txn_revenue) AS trailing_2_months_revenue +FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' +) subq_12 +INNER JOIN ( + -- Read Elements From Semantic Model 'revenue' + -- Metric Time Dimension 'ds' + -- Constrain Time Range to [2019-12-01T00:00:00, 2020-01-01T00:00:00] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , DATE_TRUNC('month', created_at) AS metric_time__month + , revenue AS txn_revenue + FROM ***************************.fct_revenue revenue_src_10006 + WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' +) subq_11 +ON + ( + subq_11.metric_time__day <= subq_12.metric_time__day + ) AND ( + subq_11.metric_time__day > DATE_TRUNC('month', subq_12.metric_time__day) + ) +WHERE subq_11.metric_time__month BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' +GROUP BY + subq_11.metric_time__month diff --git a/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql index 801df5acef..a8484a1d11 100644 --- a/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql +++ b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql @@ -9,7 +9,7 @@ FROM ( -- Pass Only Elements: -- ['count_dogs', 'metric_time__day'] SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , 1 AS count_dogs FROM ***************************.fct_animals animals_src_0 ) subq_2 diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml index 0d2369dcca..1768aeaecd 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml @@ -23,7 +23,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -68,12 +68,12 @@ - + - + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml index 99b6619da9..ab375ac0d1 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml @@ -2,41 +2,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql index b1bf877e84..cf20471005 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql @@ -39,7 +39,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -47,11 +47,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -59,11 +58,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -71,12 +69,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -84,11 +81,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -96,11 +92,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -108,9 +103,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -133,7 +127,7 @@ FROM ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -141,11 +135,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -153,14 +146,13 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -168,11 +160,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -180,9 +171,8 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index 5373f3b9a9..a33332f579 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql @@ -8,8 +8,8 @@ FROM ( 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 - , subq_9.bookings AS bookings - , subq_19.views AS views + , MAX(subq_9.bookings) AS bookings + , MAX(subq_19.views) AS views FROM ( -- Compute Metrics via Expressions SELECT @@ -54,7 +54,6 @@ FROM ( , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -66,7 +65,6 @@ FROM ( , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -78,7 +76,6 @@ FROM ( , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -90,7 +87,6 @@ FROM ( , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -102,7 +98,6 @@ FROM ( , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -114,7 +109,6 @@ FROM ( , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -126,7 +120,6 @@ FROM ( , 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_week AS metric_time__extract_week , 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 @@ -169,7 +162,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -177,11 +170,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -189,11 +181,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -201,12 +192,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -214,11 +204,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -226,11 +215,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -238,9 +226,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -269,7 +256,6 @@ FROM ( , subq_3.ds__extract_year , subq_3.ds__extract_quarter , subq_3.ds__extract_month - , subq_3.ds__extract_week , subq_3.ds__extract_day , subq_3.ds__extract_dow , subq_3.ds__extract_doy @@ -281,7 +267,6 @@ FROM ( , subq_3.created_at__extract_year , subq_3.created_at__extract_quarter , subq_3.created_at__extract_month - , subq_3.created_at__extract_week , subq_3.created_at__extract_day , subq_3.created_at__extract_dow , subq_3.created_at__extract_doy @@ -293,7 +278,6 @@ FROM ( , subq_3.listing__ds__extract_year , subq_3.listing__ds__extract_quarter , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_week , subq_3.listing__ds__extract_day , subq_3.listing__ds__extract_dow , subq_3.listing__ds__extract_doy @@ -305,7 +289,6 @@ FROM ( , 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_week , subq_3.listing__created_at__extract_day , subq_3.listing__created_at__extract_dow , subq_3.listing__created_at__extract_doy @@ -317,7 +300,6 @@ FROM ( , 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_week AS metric_time__extract_week , 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 @@ -339,7 +321,7 @@ FROM ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -347,11 +329,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -359,14 +340,13 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -374,11 +354,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -386,9 +365,8 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest @@ -409,7 +387,7 @@ FROM ( , subq_7.listing__country_latest ) subq_8 ) subq_9 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_18.ds__day @@ -453,7 +431,6 @@ FROM ( , subq_10.ds__extract_year , subq_10.ds__extract_quarter , subq_10.ds__extract_month - , subq_10.ds__extract_week , subq_10.ds__extract_day , subq_10.ds__extract_dow , subq_10.ds__extract_doy @@ -465,7 +442,6 @@ FROM ( , subq_10.ds_partitioned__extract_year , subq_10.ds_partitioned__extract_quarter , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_week , subq_10.ds_partitioned__extract_day , subq_10.ds_partitioned__extract_dow , subq_10.ds_partitioned__extract_doy @@ -477,7 +453,6 @@ FROM ( , subq_10.view__ds__extract_year , subq_10.view__ds__extract_quarter , subq_10.view__ds__extract_month - , subq_10.view__ds__extract_week , subq_10.view__ds__extract_day , subq_10.view__ds__extract_dow , subq_10.view__ds__extract_doy @@ -489,7 +464,6 @@ FROM ( , 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_week , subq_10.view__ds_partitioned__extract_day , subq_10.view__ds_partitioned__extract_dow , subq_10.view__ds_partitioned__extract_doy @@ -501,7 +475,6 @@ FROM ( , 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_week AS metric_time__extract_week , 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 @@ -514,7 +487,7 @@ FROM ( -- Read Elements From Semantic Model 'views_source' SELECT 1 AS views - , views_source_src_10009.ds AS ds__day + , DATE_TRUNC('day', views_source_src_10009.ds) AS ds__day , DATE_TRUNC('week', views_source_src_10009.ds) AS ds__week , DATE_TRUNC('month', views_source_src_10009.ds) AS ds__month , DATE_TRUNC('quarter', views_source_src_10009.ds) AS ds__quarter @@ -522,11 +495,10 @@ FROM ( , EXTRACT(year FROM views_source_src_10009.ds) AS ds__extract_year , EXTRACT(quarter FROM views_source_src_10009.ds) AS ds__extract_quarter , EXTRACT(month FROM views_source_src_10009.ds) AS ds__extract_month - , EXTRACT(week FROM views_source_src_10009.ds) AS ds__extract_week , EXTRACT(day FROM views_source_src_10009.ds) AS ds__extract_day - , EXTRACT(dow FROM views_source_src_10009.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds) AS ds__extract_dow , EXTRACT(doy FROM views_source_src_10009.ds) AS ds__extract_doy - , views_source_src_10009.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', views_source_src_10009.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS ds_partitioned__quarter @@ -534,11 +506,10 @@ FROM ( , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_doy - , views_source_src_10009.ds AS view__ds__day + , DATE_TRUNC('day', views_source_src_10009.ds) AS view__ds__day , DATE_TRUNC('week', views_source_src_10009.ds) AS view__ds__week , DATE_TRUNC('month', views_source_src_10009.ds) AS view__ds__month , DATE_TRUNC('quarter', views_source_src_10009.ds) AS view__ds__quarter @@ -546,11 +517,10 @@ FROM ( , EXTRACT(year FROM views_source_src_10009.ds) AS view__ds__extract_year , EXTRACT(quarter FROM views_source_src_10009.ds) AS view__ds__extract_quarter , EXTRACT(month FROM views_source_src_10009.ds) AS view__ds__extract_month - , EXTRACT(week FROM views_source_src_10009.ds) AS view__ds__extract_week , EXTRACT(day FROM views_source_src_10009.ds) AS view__ds__extract_day - , EXTRACT(dow FROM views_source_src_10009.ds) AS view__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds) AS view__ds__extract_dow , EXTRACT(doy FROM views_source_src_10009.ds) AS view__ds__extract_doy - , views_source_src_10009.ds_partitioned AS view__ds_partitioned__day + , DATE_TRUNC('day', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__day , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__week , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__month , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__quarter @@ -558,9 +528,8 @@ FROM ( , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_year , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_quarter , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(week FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_week , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(dow FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_dow , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_doy , views_source_src_10009.listing_id AS listing , views_source_src_10009.user_id AS user @@ -587,7 +556,6 @@ FROM ( , subq_13.ds__extract_year , subq_13.ds__extract_quarter , subq_13.ds__extract_month - , subq_13.ds__extract_week , subq_13.ds__extract_day , subq_13.ds__extract_dow , subq_13.ds__extract_doy @@ -599,7 +567,6 @@ FROM ( , subq_13.created_at__extract_year , subq_13.created_at__extract_quarter , subq_13.created_at__extract_month - , subq_13.created_at__extract_week , subq_13.created_at__extract_day , subq_13.created_at__extract_dow , subq_13.created_at__extract_doy @@ -611,7 +578,6 @@ FROM ( , subq_13.listing__ds__extract_year , subq_13.listing__ds__extract_quarter , subq_13.listing__ds__extract_month - , subq_13.listing__ds__extract_week , subq_13.listing__ds__extract_day , subq_13.listing__ds__extract_dow , subq_13.listing__ds__extract_doy @@ -623,7 +589,6 @@ FROM ( , 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_week , subq_13.listing__created_at__extract_day , subq_13.listing__created_at__extract_dow , subq_13.listing__created_at__extract_doy @@ -635,7 +600,6 @@ FROM ( , 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_week AS metric_time__extract_week , 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 @@ -657,7 +621,7 @@ FROM ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -665,11 +629,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -677,14 +640,13 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -692,11 +654,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -704,9 +665,8 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest @@ -729,20 +689,11 @@ FROM ( ) subq_19 ON ( - ( - subq_9.listing__country_latest = subq_19.listing__country_latest - ) OR ( - ( - subq_9.listing__country_latest IS NULL - ) AND ( - subq_19.listing__country_latest IS NULL - ) - ) + subq_9.listing__country_latest = subq_19.listing__country_latest ) AND ( - ( - subq_9.ds__day = subq_19.ds__day - ) OR ( - (subq_9.ds__day IS NULL) AND (subq_19.ds__day IS NULL) - ) + subq_9.ds__day = subq_19.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 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 02295e403e..b53b1f06f4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql @@ -1,82 +1,80 @@ --- Combine Metrics -- Compute Metrics via Expressions 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 - , CAST(subq_30.bookings AS DOUBLE) / CAST(NULLIF(subq_40.views, 0) AS DOUBLE) AS bookings_per_view + ds__day + , listing__country_latest + , CAST(bookings AS DOUBLE) / CAST(NULLIF(views, 0) AS DOUBLE) AS bookings_per_view FROM ( - -- Join Standard Outputs - -- Pass Only Elements: - -- ['bookings', 'listing__country_latest', 'ds__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - subq_23.ds__day AS ds__day - , listings_latest_src_10004.country AS listing__country_latest - , SUM(subq_23.bookings) AS bookings + 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Join Standard Outputs -- Pass Only Elements: - -- ['bookings', 'ds__day', 'listing'] + -- ['bookings', 'listing__country_latest', 'ds__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT - ds AS ds__day - , listing_id AS listing - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_10001 - ) subq_23 - LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 - ON - subq_23.listing = listings_latest_src_10004.listing_id - GROUP BY - subq_23.ds__day - , listings_latest_src_10004.country -) subq_30 -INNER 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_10004.country AS listing__country_latest - , SUM(subq_33.views) AS views - FROM ( - -- Read Elements From Semantic Model 'views_source' - -- Metric Time Dimension 'ds' + subq_23.ds__day AS ds__day + , listings_latest_src_10004.country AS listing__country_latest + , SUM(subq_23.bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'ds__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_23 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_23.listing = listings_latest_src_10004.listing_id + GROUP BY + subq_23.ds__day + , listings_latest_src_10004.country + ) subq_30 + FULL OUTER JOIN ( + -- Join Standard Outputs -- Pass Only Elements: - -- ['views', 'ds__day', 'listing'] + -- ['views', 'listing__country_latest', 'ds__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT - ds AS ds__day - , listing_id AS listing - , 1 AS views - FROM ***************************.fct_views views_source_src_10009 - ) subq_33 - LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + subq_33.ds__day AS ds__day + , listings_latest_src_10004.country AS listing__country_latest + , SUM(subq_33.views) AS views + FROM ( + -- Read Elements From Semantic Model 'views_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['views', 'ds__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , listing_id AS listing + , 1 AS views + FROM ***************************.fct_views views_source_src_10009 + ) subq_33 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_33.listing = listings_latest_src_10004.listing_id + GROUP BY + subq_33.ds__day + , listings_latest_src_10004.country + ) subq_40 ON - subq_33.listing = listings_latest_src_10004.listing_id - GROUP BY - subq_33.ds__day - , listings_latest_src_10004.country -) subq_40 -ON - ( ( subq_30.listing__country_latest = subq_40.listing__country_latest - ) OR ( - ( - subq_30.listing__country_latest IS NULL - ) AND ( - subq_40.listing__country_latest IS NULL - ) - ) - ) AND ( - ( + ) AND ( subq_30.ds__day = subq_40.ds__day - ) OR ( - (subq_30.ds__day IS NULL) AND (subq_40.ds__day IS NULL) ) - ) + GROUP BY + COALESCE(subq_30.ds__day, subq_40.ds__day) + , COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) +) subq_41 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql index 1bd176c115..7d16206c12 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql @@ -42,7 +42,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -50,11 +50,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -62,11 +61,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -74,12 +72,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -87,11 +84,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -99,11 +95,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -111,9 +106,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -136,7 +130,7 @@ FROM ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -144,11 +138,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -156,14 +149,13 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -171,11 +163,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -183,9 +174,8 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql index cd879426f7..2ebae4d754 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql @@ -39,7 +39,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -47,11 +47,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -59,11 +58,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -71,12 +69,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -84,11 +81,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -96,11 +92,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -108,9 +103,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -133,7 +127,7 @@ FROM ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -141,11 +135,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -153,14 +146,13 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -168,11 +160,10 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -180,9 +171,8 @@ FROM ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql index 4278be9e4c..bbb44ecc25 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql @@ -33,7 +33,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -41,11 +41,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -53,11 +52,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -65,12 +63,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -78,11 +75,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -90,11 +86,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -102,9 +97,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql index 0c8b28937a..653f418578 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql @@ -4,8 +4,8 @@ -- Metric Time Dimension 'ds' -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] SELECT - ds AS ds__day - , ds AS metric_time__day + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 -WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02' +WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02' diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql index a43457fcbd..e56a6cb7d8 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql @@ -20,7 +20,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -28,11 +28,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -40,11 +39,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -52,12 +50,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -65,11 +62,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -77,11 +73,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -89,9 +84,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql index a3ce23fb89..5cae218a31 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql @@ -26,7 +26,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -34,11 +34,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -46,11 +45,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -58,12 +56,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -71,11 +68,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -83,11 +79,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -95,9 +90,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql index c850362ca3..98241721ca 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql @@ -7,7 +7,7 @@ FROM ( -- Pass Only Elements: -- ['bookings', 'ds__day'] SELECT - ds AS ds__day + DATE_TRUNC('day', ds) AS ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_3 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql index 38492f6341..8412a752eb 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql @@ -40,7 +40,6 @@ INNER JOIN ( , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -52,7 +51,6 @@ INNER JOIN ( , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -64,7 +62,6 @@ INNER JOIN ( , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -76,7 +73,6 @@ INNER JOIN ( , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -88,7 +84,6 @@ INNER JOIN ( , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -100,7 +95,6 @@ INNER JOIN ( , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -112,7 +106,6 @@ INNER JOIN ( , 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_week AS metric_time__extract_week , 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 @@ -155,7 +148,7 @@ INNER JOIN ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -163,11 +156,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -175,11 +167,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -187,12 +178,11 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -200,11 +190,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -212,11 +201,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -224,9 +212,8 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql index 4fddfa6c2c..e3195ff6ad 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql @@ -23,12 +23,12 @@ INNER JOIN ( -- ['booking_value', 'metric_time__day', 'listing'] -- Aggregate Measures SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , SUM(booking_value) AS booking_value FROM ***************************.fct_bookings bookings_source_src_10001 GROUP BY - ds + DATE_TRUNC('day', ds) , listing_id ) subq_10 ) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql index 811955977e..6010e91d29 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -40,7 +40,6 @@ INNER JOIN ( , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -52,7 +51,6 @@ INNER JOIN ( , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -64,7 +62,6 @@ INNER JOIN ( , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -76,7 +73,6 @@ INNER JOIN ( , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -88,7 +84,6 @@ INNER JOIN ( , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -100,7 +95,6 @@ INNER JOIN ( , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -112,7 +106,6 @@ INNER JOIN ( , 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_week AS metric_time__extract_week , 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 @@ -155,7 +148,7 @@ INNER JOIN ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -163,11 +156,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -175,11 +167,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -187,12 +178,11 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -200,11 +190,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -212,11 +201,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -224,9 +212,8 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -244,4 +231,4 @@ INNER JOIN ( ) subq_3 ) subq_4 ON - CAST(subq_5.metric_time__day AS TIMESTAMP) - INTERVAL '10' day = subq_4.metric_time__day + DATE_TRUNC('day', subq_5.metric_time__day) = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql index 98efd224f9..603f3c1ac2 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -23,14 +23,14 @@ INNER JOIN ( -- ['booking_value', 'metric_time__day', 'listing'] -- Aggregate Measures SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , SUM(booking_value) AS booking_value FROM ***************************.fct_bookings bookings_source_src_10001 GROUP BY - ds + DATE_TRUNC('day', ds) , listing_id ) subq_10 ) subq_11 ON - CAST(subq_12.metric_time__day AS TIMESTAMP) - INTERVAL '10' day = subq_11.metric_time__day + DATE_TRUNC('day', subq_12.metric_time__day) = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql index 642ca46e74..c6152ec507 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql @@ -40,7 +40,6 @@ INNER JOIN ( , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -52,7 +51,6 @@ INNER JOIN ( , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -64,7 +62,6 @@ INNER JOIN ( , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -76,7 +73,6 @@ INNER JOIN ( , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -88,7 +84,6 @@ INNER JOIN ( , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -100,7 +95,6 @@ INNER JOIN ( , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -112,7 +106,6 @@ INNER JOIN ( , 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_week AS metric_time__extract_week , 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 @@ -155,7 +148,7 @@ INNER JOIN ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -163,11 +156,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -175,11 +167,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -187,12 +178,11 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -200,11 +190,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -212,11 +201,10 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -224,9 +212,8 @@ INNER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql index 1b4288571b..c22c620e3c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql @@ -23,12 +23,12 @@ INNER JOIN ( -- ['booking_value', 'metric_time__day', 'listing'] -- Aggregate Measures SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , SUM(booking_value) AS booking_value FROM ***************************.fct_bookings bookings_source_src_10001 GROUP BY - ds + DATE_TRUNC('day', ds) , listing_id ) subq_10 ) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql index dbfcb34b94..7ac33fd585 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql @@ -30,7 +30,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -38,11 +38,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -50,11 +49,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -62,12 +60,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -75,11 +72,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -87,11 +83,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -99,9 +94,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql index 7e38380b20..2ad002ed1a 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql @@ -28,7 +28,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -36,11 +36,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -48,11 +47,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -60,12 +58,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -73,11 +70,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -85,11 +81,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -97,9 +92,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -122,7 +116,7 @@ LEFT OUTER JOIN ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -130,11 +124,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -142,14 +135,13 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -157,11 +149,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -169,9 +160,8 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest @@ -196,7 +186,7 @@ LEFT OUTER JOIN ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -204,11 +194,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -216,14 +205,13 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -231,11 +219,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -243,9 +230,8 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql index d6632b499f..6abdafb81f 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql @@ -40,7 +40,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -48,11 +48,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -60,11 +59,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -72,12 +70,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -85,11 +82,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -97,11 +93,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -109,9 +104,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql index efe34b261f..b0e38b1d22 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql @@ -10,7 +10,7 @@ FROM ( -- Pass Only Elements: -- ['bookings', 'is_instant', 'ds__day'] SELECT - ds AS ds__day + DATE_TRUNC('day', ds) AS ds__day , is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql index 33fc914795..e2631c06c4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql @@ -8,7 +8,6 @@ SELECT , 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_week AS ds__extract_week , 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 @@ -20,7 +19,6 @@ SELECT , subq_0.account__ds__extract_year AS account__ds__extract_year , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter , subq_0.account__ds__extract_month AS account__ds__extract_month - , subq_0.account__ds__extract_week AS account__ds__extract_week , subq_0.account__ds__extract_day AS account__ds__extract_day , subq_0.account__ds__extract_dow AS account__ds__extract_dow , subq_0.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user @@ -77,7 +73,7 @@ INNER JOIN ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -85,12 +81,11 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -98,9 +93,8 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql index d90abbd294..3bb832607b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql @@ -8,7 +8,6 @@ SELECT , subq_3.ds__extract_year AS ds__extract_year , subq_3.ds__extract_quarter AS ds__extract_quarter , subq_3.ds__extract_month AS ds__extract_month - , subq_3.ds__extract_week AS ds__extract_week , subq_3.ds__extract_day AS ds__extract_day , subq_3.ds__extract_dow AS ds__extract_dow , subq_3.ds__extract_doy AS ds__extract_doy @@ -20,7 +19,6 @@ SELECT , subq_3.account__ds__extract_year AS account__ds__extract_year , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter , subq_3.account__ds__extract_month AS account__ds__extract_month - , subq_3.account__ds__extract_week AS account__ds__extract_week , subq_3.account__ds__extract_day AS account__ds__extract_day , subq_3.account__ds__extract_dow AS account__ds__extract_dow , subq_3.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( account_balance , account_balance AS total_account_balance_first_day , account_balance AS current_account_balance_by_user - , ds AS ds__day + , DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy , account_type - , ds AS account__ds__day + , DATE_TRUNC('day', ds) AS account__ds__day , DATE_TRUNC('week', ds) AS account__ds__week , DATE_TRUNC('month', ds) AS account__ds__month , DATE_TRUNC('quarter', ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM ds) AS account__ds__extract_year , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter , EXTRACT(month FROM ds) AS account__ds__extract_month - , EXTRACT(week FROM ds) AS account__ds__extract_week , EXTRACT(day FROM ds) AS account__ds__extract_day - , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow , EXTRACT(doy FROM ds) AS account__ds__extract_doy , account_type AS account__account_type , user_id AS user @@ -71,7 +67,7 @@ INNER JOIN ( -- Read Elements From Semantic Model 'accounts_source' -- Filter row on MIN(ds__day) SELECT - MIN(ds) AS ds__day__complete + MIN(DATE_TRUNC('day', ds)) AS ds__day__complete FROM ***************************.fct_accounts accounts_source_src_10000 ) subq_5 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql index dc98b44d95..1573868cd0 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql @@ -8,7 +8,6 @@ SELECT , 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_week AS ds__extract_week , 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 @@ -20,7 +19,6 @@ SELECT , subq_0.account__ds__extract_year AS account__ds__extract_year , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter , subq_0.account__ds__extract_month AS account__ds__extract_month - , subq_0.account__ds__extract_week AS account__ds__extract_week , subq_0.account__ds__extract_day AS account__ds__extract_day , subq_0.account__ds__extract_dow AS account__ds__extract_dow , subq_0.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user @@ -78,7 +74,7 @@ INNER JOIN ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -86,12 +82,11 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -99,9 +94,8 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql index d723157d2a..0fe5d6b65d 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql @@ -8,7 +8,6 @@ SELECT , subq_3.ds__extract_year AS ds__extract_year , subq_3.ds__extract_quarter AS ds__extract_quarter , subq_3.ds__extract_month AS ds__extract_month - , subq_3.ds__extract_week AS ds__extract_week , subq_3.ds__extract_day AS ds__extract_day , subq_3.ds__extract_dow AS ds__extract_dow , subq_3.ds__extract_doy AS ds__extract_doy @@ -20,7 +19,6 @@ SELECT , subq_3.account__ds__extract_year AS account__ds__extract_year , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter , subq_3.account__ds__extract_month AS account__ds__extract_month - , subq_3.account__ds__extract_week AS account__ds__extract_week , subq_3.account__ds__extract_day AS account__ds__extract_day , subq_3.account__ds__extract_dow AS account__ds__extract_dow , subq_3.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( account_balance , account_balance AS total_account_balance_first_day , account_balance AS current_account_balance_by_user - , ds AS ds__day + , DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy , account_type - , ds AS account__ds__day + , DATE_TRUNC('day', ds) AS account__ds__day , DATE_TRUNC('week', ds) AS account__ds__week , DATE_TRUNC('month', ds) AS account__ds__month , DATE_TRUNC('quarter', ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM ds) AS account__ds__extract_year , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter , EXTRACT(month FROM ds) AS account__ds__extract_month - , EXTRACT(week FROM ds) AS account__ds__extract_week , EXTRACT(day FROM ds) AS account__ds__extract_day - , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow , EXTRACT(doy FROM ds) AS account__ds__extract_doy , account_type AS account__account_type , user_id AS user @@ -72,7 +68,7 @@ INNER JOIN ( -- Filter row on MAX(ds__day) SELECT user_id AS user - , MAX(ds) AS ds__day__complete + , MAX(DATE_TRUNC('day', ds)) AS ds__day__complete FROM ***************************.fct_accounts accounts_source_src_10000 GROUP BY user_id diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql index 95274f2863..4cd48b4c62 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql @@ -8,7 +8,6 @@ SELECT , 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_week AS ds__extract_week , 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 @@ -20,7 +19,6 @@ SELECT , subq_0.account__ds__extract_year AS account__ds__extract_year , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter , subq_0.account__ds__extract_month AS account__ds__extract_month - , subq_0.account__ds__extract_week AS account__ds__extract_week , subq_0.account__ds__extract_day AS account__ds__extract_day , subq_0.account__ds__extract_dow AS account__ds__extract_dow , subq_0.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user @@ -78,7 +74,7 @@ INNER JOIN ( accounts_source_src_10000.account_balance , accounts_source_src_10000.account_balance AS total_account_balance_first_day , accounts_source_src_10000.account_balance AS current_account_balance_by_user - , accounts_source_src_10000.ds AS ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter @@ -86,12 +82,11 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy , accounts_source_src_10000.account_type - , accounts_source_src_10000.ds AS account__ds__day + , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter @@ -99,9 +94,8 @@ INNER JOIN ( , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month - , EXTRACT(week FROM accounts_source_src_10000.ds) AS account__ds__extract_week , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day - , EXTRACT(dow FROM accounts_source_src_10000.ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy , accounts_source_src_10000.account_type AS account__account_type , accounts_source_src_10000.user_id AS user diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql index e0c877bdf1..2b23979547 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql @@ -8,7 +8,6 @@ SELECT , subq_3.ds__extract_year AS ds__extract_year , subq_3.ds__extract_quarter AS ds__extract_quarter , subq_3.ds__extract_month AS ds__extract_month - , subq_3.ds__extract_week AS ds__extract_week , subq_3.ds__extract_day AS ds__extract_day , subq_3.ds__extract_dow AS ds__extract_dow , subq_3.ds__extract_doy AS ds__extract_doy @@ -20,7 +19,6 @@ SELECT , subq_3.account__ds__extract_year AS account__ds__extract_year , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter , subq_3.account__ds__extract_month AS account__ds__extract_month - , subq_3.account__ds__extract_week AS account__ds__extract_week , subq_3.account__ds__extract_day AS account__ds__extract_day , subq_3.account__ds__extract_dow AS account__ds__extract_dow , subq_3.account__ds__extract_doy AS account__ds__extract_doy @@ -37,7 +35,7 @@ FROM ( account_balance , account_balance AS total_account_balance_first_day , account_balance AS current_account_balance_by_user - , ds AS ds__day + , DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -45,12 +43,11 @@ FROM ( , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy , account_type - , ds AS account__ds__day + , DATE_TRUNC('day', ds) AS account__ds__day , DATE_TRUNC('week', ds) AS account__ds__week , DATE_TRUNC('month', ds) AS account__ds__month , DATE_TRUNC('quarter', ds) AS account__ds__quarter @@ -58,9 +55,8 @@ FROM ( , EXTRACT(year FROM ds) AS account__ds__extract_year , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter , EXTRACT(month FROM ds) AS account__ds__extract_month - , EXTRACT(week FROM ds) AS account__ds__extract_week , EXTRACT(day FROM ds) AS account__ds__extract_day - , EXTRACT(dow FROM ds) AS account__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow , EXTRACT(doy FROM ds) AS account__ds__extract_doy , account_type AS account__account_type , user_id AS user @@ -72,7 +68,7 @@ INNER JOIN ( -- Filter row on MIN(ds__day) SELECT DATE_TRUNC('week', ds) AS ds__week - , MIN(ds) AS ds__day__complete + , MIN(DATE_TRUNC('day', ds)) AS ds__day__complete FROM ***************************.fct_accounts accounts_source_src_10000 GROUP BY DATE_TRUNC('week', ds) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql index 9c6e0a2676..73da0ff4d9 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql @@ -26,7 +26,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -34,11 +34,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -46,11 +45,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -58,12 +56,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -71,11 +68,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -83,11 +79,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -95,9 +90,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -120,7 +114,7 @@ LEFT OUTER JOIN ( 1 AS listings , listings_latest_src_10004.capacity AS largest_listing , listings_latest_src_10004.capacity AS smallest_listing - , listings_latest_src_10004.created_at AS ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter @@ -128,11 +122,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , listings_latest_src_10004.created_at AS created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter @@ -140,14 +133,13 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy , listings_latest_src_10004.country AS country_latest , listings_latest_src_10004.is_lux AS is_lux_latest , listings_latest_src_10004.capacity AS capacity_latest - , listings_latest_src_10004.created_at AS listing__ds__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter @@ -155,11 +147,10 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__ds__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , listings_latest_src_10004.created_at AS listing__created_at__day + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter @@ -167,9 +158,8 @@ LEFT OUTER JOIN ( , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(week FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_week , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(dow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy , listings_latest_src_10004.country AS listing__country_latest , listings_latest_src_10004.is_lux AS listing__is_lux_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql index b9ae7f84a4..d04bcf5afc 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql @@ -15,7 +15,7 @@ SELECT , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -23,11 +23,10 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -35,11 +34,10 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -47,12 +45,11 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -60,11 +57,10 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -72,11 +68,10 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -84,9 +79,8 @@ SELECT , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql index d1560d9ab0..433a78e339 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql @@ -15,7 +15,7 @@ SELECT , booking_value AS approximate_continuous_booking_value_p99 , booking_value AS approximate_discrete_booking_value_p99 , is_instant - , ds AS ds__day + , DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -23,11 +23,10 @@ SELECT , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy - , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter @@ -35,11 +34,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy - , paid_at AS paid_at__day + , DATE_TRUNC('day', paid_at) AS paid_at__day , DATE_TRUNC('week', paid_at) AS paid_at__week , DATE_TRUNC('month', paid_at) AS paid_at__month , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter @@ -47,12 +45,11 @@ SELECT , EXTRACT(year FROM paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS paid_at__extract_month - , EXTRACT(week FROM paid_at) AS paid_at__extract_week , EXTRACT(day FROM paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy , is_instant AS booking__is_instant - , ds AS booking__ds__day + , DATE_TRUNC('day', ds) AS booking__ds__day , DATE_TRUNC('week', ds) AS booking__ds__week , DATE_TRUNC('month', ds) AS booking__ds__month , DATE_TRUNC('quarter', ds) AS booking__ds__quarter @@ -60,11 +57,10 @@ SELECT , EXTRACT(year FROM ds) AS booking__ds__extract_year , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter , EXTRACT(month FROM ds) AS booking__ds__extract_month - , EXTRACT(week FROM ds) AS booking__ds__extract_week , EXTRACT(day FROM ds) AS booking__ds__extract_day - , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow , EXTRACT(doy FROM ds) AS booking__ds__extract_doy - , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter @@ -72,11 +68,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy - , paid_at AS booking__paid_at__day + , DATE_TRUNC('day', paid_at) AS booking__paid_at__day , DATE_TRUNC('week', paid_at) AS booking__paid_at__week , DATE_TRUNC('month', paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter @@ -84,9 +79,8 @@ SELECT , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy , listing_id AS listing , guest_id AS guest diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql new file mode 100644 index 0000000000..49c690395d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql @@ -0,0 +1,447 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.referred_bookings AS ref_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.referred_bookings) AS referred_bookings + FROM ( + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.referred_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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_8.metric_time__day + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + ON + subq_4.metric_time__day = subq_9.metric_time__day + GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) +) subq_10 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql new file mode 100644 index 0000000000..f7d37d45b3 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql @@ -0,0 +1,53 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) AS metric_time__day + , MAX(subq_15.ref_bookings) AS ref_bookings + , MAX(subq_20.bookings) AS bookings + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(referred_bookings) AS ref_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + GROUP BY + metric_time__day + ) subq_15 + FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + GROUP BY + metric_time__day + ) subq_20 + ON + subq_15.metric_time__day = subq_20.metric_time__day + GROUP BY + COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) +) subq_21 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql new file mode 100644 index 0000000000..ae1243737c --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -0,0 +1,547 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + ) subq_11 + ) subq_12 + ON + subq_4.metric_time__day = subq_12.metric_time__day + GROUP BY + COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql new file mode 100644 index 0000000000..6d1b17b416 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -0,0 +1,57 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__day + ) subq_18 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + GROUP BY + subq_22.ds + ) subq_26 + ON + subq_18.metric_time__day = subq_26.metric_time__day + GROUP BY + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql new file mode 100644 index 0000000000..e32be63ced --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -0,0 +1,548 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__week + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__week + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__week + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__week'] + SELECT + subq_1.metric_time__week + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + GROUP BY + subq_10.metric_time__week + ) subq_11 + ) subq_12 + ON + subq_4.metric_time__week = subq_12.metric_time__week + GROUP BY + COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..5b18fcfa5f --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__week + , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__week + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__week'] + SELECT + DATE_TRUNC('week', ds) AS metric_time__week + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__week + ) subq_18 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + GROUP BY + DATE_TRUNC('week', subq_22.ds) + ) subq_26 + ON + subq_18.metric_time__week = subq_26.metric_time__week + GROUP BY + COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql new file mode 100644 index 0000000000..14c9ec1451 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -0,0 +1,547 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + ) subq_11 + ) subq_12 + ON + subq_4.metric_time__day = subq_12.metric_time__day + GROUP BY + COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql new file mode 100644 index 0000000000..e4680b0c3b --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -0,0 +1,57 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__day + ) subq_18 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + GROUP BY + subq_22.ds + ) subq_26 + ON + subq_18.metric_time__day = subq_26.metric_time__day + GROUP BY + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql new file mode 100644 index 0000000000..696061840e --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -0,0 +1,547 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__quarter + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__quarter + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__quarter + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__quarter'] + SELECT + subq_1.metric_time__quarter + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__quarter + ) subq_11 + ) subq_12 + ON + subq_4.metric_time__quarter = subq_12.metric_time__quarter + GROUP BY + COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..e45ac7276d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -0,0 +1,57 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__quarter + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__quarter + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__quarter'] + SELECT + DATE_TRUNC('quarter', ds) AS metric_time__quarter + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__quarter + ) subq_18 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + GROUP BY + DATE_TRUNC('quarter', subq_22.ds) + ) subq_26 + ON + subq_18.metric_time__quarter = subq_26.metric_time__quarter + GROUP BY + COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql new file mode 100644 index 0000000000..7fd3f09a14 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -0,0 +1,647 @@ +-- Compute Metrics via Expressions +SELECT + subq_16.metric_time__day + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.bookings AS month_start_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_14.metric_time__day + , subq_14.bookings AS bookings_1_month_ago + FROM ( + -- Aggregate Measures + SELECT + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_12.metric_time__day + , subq_12.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_10.metric_time__day AS metric_time__day + , 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 + FROM ( + -- Date Spine + SELECT + 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 ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_8 + ) subq_9 + ON + DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day + ) subq_12 + ) subq_13 + GROUP BY + subq_13.metric_time__day + ) subq_14 + ) subq_15 + ON + subq_7.metric_time__day = subq_15.metric_time__day + GROUP BY + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql new file mode 100644 index 0000000000..126a2a6467 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -0,0 +1,61 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + 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 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + ON + DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + GROUP BY + subq_20.ds + ) subq_24 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_26 + ON + DATE_TRUNC('month', subq_28.ds) = subq_26.metric_time__day + GROUP BY + subq_28.ds + ) subq_32 + ON + subq_24.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql new file mode 100644 index 0000000000..87d0d91c22 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -0,0 +1,648 @@ +-- Compute Metrics via Expressions +SELECT + subq_16.metric_time__year + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__year + , subq_6.bookings AS month_start_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__year'] + SELECT + subq_4.metric_time__year + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + DATE_TRUNC('year', subq_2.metric_time__day) 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + GROUP BY + subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_14.metric_time__year + , subq_14.bookings AS bookings_1_month_ago + FROM ( + -- Aggregate Measures + SELECT + subq_13.metric_time__year + , SUM(subq_13.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__year'] + SELECT + subq_12.metric_time__year + , subq_12.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , 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 + FROM ( + -- Date Spine + SELECT + 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 ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_8 + ) subq_9 + ON + DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day + ) subq_12 + ) subq_13 + GROUP BY + subq_13.metric_time__year + ) subq_14 + ) subq_15 + ON + subq_7.metric_time__year = subq_15.metric_time__year + GROUP BY + COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) +) subq_16 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql new file mode 100644 index 0000000000..80083c008d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__year + , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior +FROM ( + -- Combine Metrics + 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 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + ON + DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + GROUP BY + DATE_TRUNC('year', subq_20.ds) + ) subq_24 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_26 + ON + DATE_TRUNC('month', subq_28.ds) = subq_26.metric_time__day + GROUP BY + DATE_TRUNC('year', subq_28.ds) + ) subq_32 + ON + subq_24.metric_time__year = subq_32.metric_time__year + GROUP BY + COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) +) subq_33 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql new file mode 100644 index 0000000000..a1e0e15156 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -0,0 +1,561 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_3.metric_time__day + , SUM(subq_3.bookings) AS bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_6 + ) subq_7 + ON + DATE_TRUNC('day', subq_8.metric_time__day) = subq_7.metric_time__day + ) subq_10 + ) subq_11 + WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_5.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql new file mode 100644 index 0000000000..1b158e1887 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -0,0 +1,66 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Constrain Output with WHERE + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_18 + WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' + GROUP BY + metric_time__day + ) subq_21 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings_2_weeks_ago + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_23 + ON + DATE_TRUNC('day', subq_25.ds) = subq_23.metric_time__day + ) subq_27 + WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' + GROUP BY + metric_time__day + ) subq_30 + ON + subq_21.metric_time__day = subq_30.metric_time__day + GROUP BY + COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) +) subq_31 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql new file mode 100644 index 0000000000..cdd0f927f5 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -0,0 +1,434 @@ +-- Compute Metrics via Expressions +SELECT + 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_9.metric_time__day + , subq_9.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 + FROM ( + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_7.metric_time__day + , subq_7.bookers + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_5.metric_time__day AS metric_time__day + , 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 + FROM ( + -- Date Spine + SELECT + 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + ) + ) subq_4 + ON + DATE_TRUNC('day', subq_5.metric_time__day) = subq_4.metric_time__day + ) subq_7 + ) subq_8 + GROUP BY + subq_8.metric_time__day + ) subq_9 +) subq_10 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql new file mode 100644 index 0000000000..ac6ff46f0c --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -0,0 +1,34 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Join Self Over Time Range + SELECT + subq_14.ds AS metric_time__day + , bookings_source_src_10001.guest_id AS bookers + FROM ***************************.mf_time_spine subq_14 + INNER JOIN + ***************************.fct_bookings bookings_source_src_10001 + ON + ( + DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_14.ds + ) AND ( + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_14.ds) + ) + ) subq_15 + ON + DATE_TRUNC('day', subq_17.ds) = subq_15.metric_time__day + GROUP BY + subq_17.ds +) subq_21 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql new file mode 100644 index 0000000000..b3e657945d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -0,0 +1,320 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('day', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql new file mode 100644 index 0000000000..29d6978951 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -0,0 +1,27 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings_5_days_ago AS bookings_5_day_lag +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + ON + DATE_TRUNC('day', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql new file mode 100644 index 0000000000..1d2d351788 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql @@ -0,0 +1,899 @@ +-- Compute Metrics via Expressions +SELECT + subq_22.metric_time__day + , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred + FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.referred_bookings AS ref_bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.referred_bookings) AS referred_bookings + FROM ( + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.referred_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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_8.metric_time__day + , subq_8.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + ON + subq_4.metric_time__day = subq_9.metric_time__day + GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) + ) subq_10 + ) subq_11 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__day + , subq_15.instant_bookings AS instant + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__day + , SUM(subq_14.instant_bookings) AS instant_bookings + FROM ( + -- Pass Only Elements: + -- ['instant_bookings', 'metric_time__day'] + SELECT + subq_13.metric_time__day + , subq_13.instant_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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_12 + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__day + ) subq_15 + ) subq_16 + ON + subq_11.metric_time__day = subq_16.metric_time__day + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_20.metric_time__day + , subq_20.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_19.metric_time__day + , SUM(subq_19.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_18.metric_time__day + , subq_18.bookings + FROM ( + -- Metric Time Dimension 'ds' + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_17 + ) subq_18 + ) subq_19 + GROUP BY + subq_19.metric_time__day + ) subq_20 + ) subq_21 + ON + COALESCE(subq_11.metric_time__day, subq_16.metric_time__day) = subq_21.metric_time__day + GROUP BY + COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day) +) subq_22 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql new file mode 100644 index 0000000000..86124d9091 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql @@ -0,0 +1,111 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day) AS metric_time__day + , MAX(subq_34.non_referred) AS non_referred + , MAX(subq_39.instant) AS instant + , MAX(subq_44.bookings) AS bookings + FROM ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , (bookings - ref_bookings) * 1.0 / bookings AS non_referred + FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.ref_bookings) AS ref_bookings + , MAX(subq_32.bookings) AS bookings + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(referred_bookings) AS ref_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['referred_bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_25 + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_30 + GROUP BY + metric_time__day + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) + ) subq_33 + ) subq_34 + FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(instant_bookings) AS instant + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['instant_bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_37 + GROUP BY + metric_time__day + ) subq_39 + ON + subq_34.metric_time__day = subq_39.metric_time__day + FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_42 + GROUP BY + metric_time__day + ) subq_44 + ON + COALESCE(subq_34.metric_time__day, subq_39.metric_time__day) = subq_44.metric_time__day + GROUP BY + COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day) +) subq_45 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql new file mode 100644 index 0000000000..3a7aa46753 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql @@ -0,0 +1,342 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__day + , COALESCE(subq_9.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 + FROM ( + -- Date Spine + SELECT + subq_8.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_8 + ) subq_7 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , COUNT(DISTINCT subq_5.bookers) AS bookers + FROM ( + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + ) + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ON + subq_7.metric_time__day = subq_6.metric_time__day +) subq_9 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql new file mode 100644 index 0000000000..9d7a4e4446 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , COALESCE(bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 +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 + 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 + , COUNT(DISTINCT bookings_source_src_10001.guest_id) AS bookers + FROM ***************************.mf_time_spine subq_13 + INNER JOIN + ***************************.fct_bookings bookings_source_src_10001 + ON + ( + DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_13.ds + ) AND ( + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_13.ds) + ) + GROUP BY + subq_13.ds + ) subq_16 + ON + subq_18.ds = subq_16.metric_time__day +) subq_19 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql new file mode 100644 index 0000000000..a8b1eb779c --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -0,0 +1,561 @@ +-- Compute Metrics via Expressions +SELECT + subq_16.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 Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , COALESCE(subq_6.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 + FROM ( + -- Date Spine + SELECT + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ON + subq_4.metric_time__day = subq_3.metric_time__day + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_14.metric_time__day + , subq_14.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_12.metric_time__day + , subq_12.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_10.metric_time__day AS metric_time__day + , 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 + FROM ( + -- Date Spine + SELECT + 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 ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_8 + ) subq_9 + ON + DATE_TRUNC('day', subq_10.metric_time__day) = subq_9.metric_time__day + ) subq_12 + ) subq_13 + GROUP BY + subq_13.metric_time__day + ) subq_14 + ) subq_15 + ON + subq_7.metric_time__day = subq_15.metric_time__day + GROUP BY + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql new file mode 100644 index 0000000000..1178cac9b1 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -0,0 +1,71 @@ +-- Compute Metrics via Expressions +SELECT + 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 Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 + 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 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_19 + GROUP BY + metric_time__day + ) subq_20 + ON + subq_22.ds = subq_20.metric_time__day + ) subq_23 + ) subq_24 + 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_26 + ON + DATE_TRUNC('day', subq_28.ds) = subq_26.metric_time__day + GROUP BY + subq_28.ds + ) subq_32 + ON + subq_24.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql new file mode 100644 index 0000000000..8de2818d2b --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -0,0 +1,228 @@ +-- Compute Metrics via Expressions +SELECT + subq_6.metric_time__day + , COALESCE(subq_6.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 + FROM ( + -- Date Spine + SELECT + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ON + subq_4.metric_time__day = subq_3.metric_time__day +) subq_6 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql new file mode 100644 index 0000000000..adeb9c3151 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql @@ -0,0 +1,31 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 +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 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + GROUP BY + metric_time__day + ) subq_10 + ON + subq_12.ds = subq_10.metric_time__day +) subq_13 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql new file mode 100644 index 0000000000..b1d689ff06 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_6.metric_time__month + , COALESCE(subq_6.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 + FROM ( + -- Date Spine + SELECT + DATE_TRUNC('month', subq_5.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_5 + GROUP BY + DATE_TRUNC('month', subq_5.ds) + ) subq_4 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_2.metric_time__month + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__month'] + SELECT + subq_1.metric_time__month + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__month + ) subq_3 + ON + subq_4.metric_time__month = subq_3.metric_time__month +) subq_6 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql new file mode 100644 index 0000000000..9b48edbdd6 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql @@ -0,0 +1,38 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_11.metric_time__month AS metric_time__month + , subq_10.bookings AS bookings + FROM ( + -- Date Spine + SELECT + DATE_TRUNC('month', ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_12 + GROUP BY + DATE_TRUNC('month', ds) + ) subq_11 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + metric_time__month + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__month'] + SELECT + DATE_TRUNC('month', ds) AS metric_time__month + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + GROUP BY + metric_time__month + ) subq_10 + ON + subq_11.metric_time__month = subq_10.metric_time__month +) subq_13 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..eefd911947 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql @@ -0,0 +1,214 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.booking__is_instant + , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0 +FROM ( + -- Aggregate Measures + SELECT + subq_2.booking__is_instant + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant'] + SELECT + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.booking__is_instant +) subq_3 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..f2e8924fa6 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,22 @@ +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 +FROM ( + -- Aggregate Measures + SELECT + booking__is_instant + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant'] + SELECT + is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_6 + GROUP BY + booking__is_instant +) subq_7 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql new file mode 100644 index 0000000000..ab39f91c86 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql @@ -0,0 +1,214 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.booking__paid_at__day + , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0 +FROM ( + -- Aggregate Measures + SELECT + subq_2.booking__paid_at__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'booking__paid_at__day'] + SELECT + subq_1.booking__paid_at__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.booking__paid_at__day +) subq_3 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql new file mode 100644 index 0000000000..52e3a373c3 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql @@ -0,0 +1,22 @@ +-- Compute Metrics via Expressions +SELECT + booking__paid_at__day + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 +FROM ( + -- Aggregate Measures + SELECT + booking__paid_at__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'booking__paid_at__day'] + SELECT + DATE_TRUNC('day', paid_at) AS booking__paid_at__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_6 + GROUP BY + booking__paid_at__day +) subq_7 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql new file mode 100644 index 0000000000..e08feb9c72 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql @@ -0,0 +1,214 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.metric_time__day + , COALESCE(subq_3.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 + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day +) subq_3 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql new file mode 100644 index 0000000000..a96360ac38 --- /dev/null +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql @@ -0,0 +1,22 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine +FROM ( + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_6 + GROUP BY + metric_time__day +) subq_7 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql new file mode 100644 index 0000000000..68af4ecdc9 --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -0,0 +1,547 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__extract_dow + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__extract_dow + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__extract_dow + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + subq_1.metric_time__extract_dow + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , 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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ON + DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__extract_dow + ) subq_11 + ) subq_12 + ON + subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + GROUP BY + COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) +) subq_13 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql new file mode 100644 index 0000000000..5dcc27cbef --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql @@ -0,0 +1,57 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__extract_dow + , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__extract_dow + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_16 + GROUP BY + metric_time__extract_dow + ) subq_18 + FULL OUTER JOIN ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + EXTRACT(DAY_OF_WEEK FROM subq_22.ds) AS metric_time__extract_dow + , SUM(subq_20.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_22 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_20 + ON + DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + GROUP BY + EXTRACT(DAY_OF_WEEK FROM subq_22.ds) + ) subq_26 + ON + subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow + GROUP BY + COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) +) subq_27 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql new file mode 100644 index 0000000000..34e8a1db84 --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql @@ -0,0 +1,214 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.metric_time__extract_dow + , subq_3.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__extract_dow + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + subq_1.metric_time__extract_dow + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__extract_dow +) subq_3 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql new file mode 100644 index 0000000000..2466bb697d --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__extract_dow + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__extract_dow'] + SELECT + EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_6 +GROUP BY + metric_time__extract_dow diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql new file mode 100644 index 0000000000..2ed67b0ebb --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql @@ -0,0 +1,240 @@ +-- 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 +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 + FROM ( + -- Pass Only Elements: + -- ['bookings', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'metric_time__extract_month', + -- 'metric_time__extract_quarter', + -- '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 + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + 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 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql new file mode 100644 index 0000000000..8e17b03eb3 --- /dev/null +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql @@ -0,0 +1,38 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__extract_year + , metric_time__extract_quarter + , metric_time__extract_month + , metric_time__extract_day + , metric_time__extract_dow + , metric_time__extract_doy + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'metric_time__extract_month', + -- 'metric_time__extract_quarter', + -- 'metric_time__extract_year'] + SELECT + EXTRACT(year FROM ds) AS metric_time__extract_year + , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter + , EXTRACT(month FROM ds) AS metric_time__extract_month + , EXTRACT(day FROM ds) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow + , EXTRACT(doy FROM ds) AS metric_time__extract_doy + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_6 +GROUP BY + metric_time__extract_year + , metric_time__extract_quarter + , metric_time__extract_month + , metric_time__extract_day + , metric_time__extract_dow + , metric_time__extract_doy diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql index e9ab8e5153..28d7cd941d 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql @@ -8,7 +8,6 @@ SELECT , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -20,7 +19,6 @@ SELECT , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -32,7 +30,6 @@ SELECT , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -44,7 +41,6 @@ SELECT , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -56,7 +52,6 @@ SELECT , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -68,7 +63,6 @@ SELECT , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -80,7 +74,6 @@ SELECT , subq_0.paid_at__extract_year AS metric_time__extract_year , subq_0.paid_at__extract_quarter AS metric_time__extract_quarter , subq_0.paid_at__extract_month AS metric_time__extract_month - , subq_0.paid_at__extract_week AS metric_time__extract_week , subq_0.paid_at__extract_day AS metric_time__extract_day , subq_0.paid_at__extract_dow AS metric_time__extract_dow , subq_0.paid_at__extract_doy AS metric_time__extract_doy @@ -111,7 +104,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -119,11 +112,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -131,11 +123,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -143,12 +134,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -156,11 +146,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -168,11 +157,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -180,9 +168,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql index 00e036ec03..6a63f5fde6 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'paid_at' SELECT - ds AS ds__day + DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -9,11 +9,10 @@ SELECT , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy - , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter @@ -21,11 +20,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy - , paid_at AS paid_at__day + , DATE_TRUNC('day', paid_at) AS paid_at__day , DATE_TRUNC('week', paid_at) AS paid_at__week , DATE_TRUNC('month', paid_at) AS paid_at__month , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter @@ -33,11 +31,10 @@ SELECT , EXTRACT(year FROM paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS paid_at__extract_month - , EXTRACT(week FROM paid_at) AS paid_at__extract_week , EXTRACT(day FROM paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy - , ds AS booking__ds__day + , DATE_TRUNC('day', ds) AS booking__ds__day , DATE_TRUNC('week', ds) AS booking__ds__week , DATE_TRUNC('month', ds) AS booking__ds__month , DATE_TRUNC('quarter', ds) AS booking__ds__quarter @@ -45,11 +42,10 @@ SELECT , EXTRACT(year FROM ds) AS booking__ds__extract_year , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter , EXTRACT(month FROM ds) AS booking__ds__extract_month - , EXTRACT(week FROM ds) AS booking__ds__extract_week , EXTRACT(day FROM ds) AS booking__ds__extract_day - , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow , EXTRACT(doy FROM ds) AS booking__ds__extract_doy - , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter @@ -57,11 +53,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy - , paid_at AS booking__paid_at__day + , DATE_TRUNC('day', paid_at) AS booking__paid_at__day , DATE_TRUNC('week', paid_at) AS booking__paid_at__week , DATE_TRUNC('month', paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter @@ -69,11 +64,10 @@ SELECT , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy - , paid_at AS metric_time__day + , DATE_TRUNC('day', paid_at) AS metric_time__day , DATE_TRUNC('week', paid_at) AS metric_time__week , DATE_TRUNC('month', paid_at) AS metric_time__month , DATE_TRUNC('quarter', paid_at) AS metric_time__quarter @@ -81,9 +75,8 @@ SELECT , EXTRACT(year FROM paid_at) AS metric_time__extract_year , EXTRACT(quarter FROM paid_at) AS metric_time__extract_quarter , EXTRACT(month FROM paid_at) AS metric_time__extract_month - , EXTRACT(week FROM paid_at) AS metric_time__extract_week , EXTRACT(day FROM paid_at) AS metric_time__extract_day - , EXTRACT(dow FROM paid_at) AS metric_time__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS metric_time__extract_dow , EXTRACT(doy FROM paid_at) AS metric_time__extract_doy , listing_id AS listing , guest_id AS guest diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql index e2cc747ae2..1de66ca95f 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql @@ -8,7 +8,6 @@ SELECT , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -20,7 +19,6 @@ SELECT , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -32,7 +30,6 @@ SELECT , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -44,7 +41,6 @@ SELECT , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -56,7 +52,6 @@ SELECT , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -68,7 +63,6 @@ SELECT , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -80,7 +74,6 @@ SELECT , 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_week AS metric_time__extract_week , 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 @@ -123,7 +116,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -131,11 +124,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -143,11 +135,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -155,12 +146,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -168,11 +158,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -180,11 +169,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -192,9 +180,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql index c6d742fae0..8d46cda654 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' SELECT - ds AS ds__day + DATE_TRUNC('day', ds) AS ds__day , DATE_TRUNC('week', ds) AS ds__week , DATE_TRUNC('month', ds) AS ds__month , DATE_TRUNC('quarter', ds) AS ds__quarter @@ -9,11 +9,10 @@ SELECT , EXTRACT(year FROM ds) AS ds__extract_year , EXTRACT(quarter FROM ds) AS ds__extract_quarter , EXTRACT(month FROM ds) AS ds__extract_month - , EXTRACT(week FROM ds) AS ds__extract_week , EXTRACT(day FROM ds) AS ds__extract_day - , EXTRACT(dow FROM ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow , EXTRACT(doy FROM ds) AS ds__extract_doy - , ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter @@ -21,11 +20,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy - , paid_at AS paid_at__day + , DATE_TRUNC('day', paid_at) AS paid_at__day , DATE_TRUNC('week', paid_at) AS paid_at__week , DATE_TRUNC('month', paid_at) AS paid_at__month , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter @@ -33,11 +31,10 @@ SELECT , EXTRACT(year FROM paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS paid_at__extract_month - , EXTRACT(week FROM paid_at) AS paid_at__extract_week , EXTRACT(day FROM paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy - , ds AS booking__ds__day + , DATE_TRUNC('day', ds) AS booking__ds__day , DATE_TRUNC('week', ds) AS booking__ds__week , DATE_TRUNC('month', ds) AS booking__ds__month , DATE_TRUNC('quarter', ds) AS booking__ds__quarter @@ -45,11 +42,10 @@ SELECT , EXTRACT(year FROM ds) AS booking__ds__extract_year , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter , EXTRACT(month FROM ds) AS booking__ds__extract_month - , EXTRACT(week FROM ds) AS booking__ds__extract_week , EXTRACT(day FROM ds) AS booking__ds__extract_day - , EXTRACT(dow FROM ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow , EXTRACT(doy FROM ds) AS booking__ds__extract_doy - , ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter @@ -57,11 +53,10 @@ SELECT , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy - , paid_at AS booking__paid_at__day + , DATE_TRUNC('day', paid_at) AS booking__paid_at__day , DATE_TRUNC('week', paid_at) AS booking__paid_at__week , DATE_TRUNC('month', paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter @@ -69,11 +64,10 @@ SELECT , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy - , ds AS metric_time__day + , DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week , DATE_TRUNC('month', ds) AS metric_time__month , DATE_TRUNC('quarter', ds) AS metric_time__quarter @@ -81,9 +75,8 @@ SELECT , EXTRACT(year FROM ds) AS metric_time__extract_year , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter , EXTRACT(month FROM ds) AS metric_time__extract_month - , EXTRACT(week FROM ds) AS metric_time__extract_week , EXTRACT(day FROM ds) AS metric_time__extract_day - , EXTRACT(dow FROM ds) AS metric_time__extract_dow + , EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow , EXTRACT(doy FROM ds) AS metric_time__extract_doy , listing_id AS listing , guest_id AS guest diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql index c88105f92d..f0da22acac 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql @@ -30,7 +30,6 @@ FROM ( , subq_0.ds__extract_year , subq_0.ds__extract_quarter , subq_0.ds__extract_month - , subq_0.ds__extract_week , subq_0.ds__extract_day , subq_0.ds__extract_dow , subq_0.ds__extract_doy @@ -42,7 +41,6 @@ FROM ( , subq_0.ds_partitioned__extract_year , subq_0.ds_partitioned__extract_quarter , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_week , subq_0.ds_partitioned__extract_day , subq_0.ds_partitioned__extract_dow , subq_0.ds_partitioned__extract_doy @@ -54,7 +52,6 @@ FROM ( , subq_0.paid_at__extract_year , subq_0.paid_at__extract_quarter , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_week , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy @@ -66,7 +63,6 @@ FROM ( , subq_0.booking__ds__extract_year , subq_0.booking__ds__extract_quarter , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_week , subq_0.booking__ds__extract_day , subq_0.booking__ds__extract_dow , subq_0.booking__ds__extract_doy @@ -78,7 +74,6 @@ FROM ( , 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_week , subq_0.booking__ds_partitioned__extract_day , subq_0.booking__ds_partitioned__extract_dow , subq_0.booking__ds_partitioned__extract_doy @@ -90,7 +85,6 @@ FROM ( , 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_week , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy @@ -102,7 +96,6 @@ FROM ( , 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_week AS metric_time__extract_week , 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 @@ -145,7 +138,7 @@ FROM ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -153,11 +146,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -165,11 +157,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -177,12 +168,11 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -190,11 +180,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -202,11 +191,10 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -214,9 +202,8 @@ FROM ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest @@ -259,7 +246,6 @@ FULL OUTER JOIN ( , subq_5.ds__extract_year , subq_5.ds__extract_quarter , subq_5.ds__extract_month - , subq_5.ds__extract_week , subq_5.ds__extract_day , subq_5.ds__extract_dow , subq_5.ds__extract_doy @@ -271,7 +257,6 @@ FULL OUTER JOIN ( , subq_5.ds_partitioned__extract_year , subq_5.ds_partitioned__extract_quarter , subq_5.ds_partitioned__extract_month - , subq_5.ds_partitioned__extract_week , subq_5.ds_partitioned__extract_day , subq_5.ds_partitioned__extract_dow , subq_5.ds_partitioned__extract_doy @@ -283,7 +268,6 @@ FULL OUTER JOIN ( , subq_5.paid_at__extract_year , subq_5.paid_at__extract_quarter , subq_5.paid_at__extract_month - , subq_5.paid_at__extract_week , subq_5.paid_at__extract_day , subq_5.paid_at__extract_dow , subq_5.paid_at__extract_doy @@ -295,7 +279,6 @@ FULL OUTER JOIN ( , subq_5.booking__ds__extract_year , subq_5.booking__ds__extract_quarter , subq_5.booking__ds__extract_month - , subq_5.booking__ds__extract_week , subq_5.booking__ds__extract_day , subq_5.booking__ds__extract_dow , subq_5.booking__ds__extract_doy @@ -307,7 +290,6 @@ FULL OUTER JOIN ( , 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_week , subq_5.booking__ds_partitioned__extract_day , subq_5.booking__ds_partitioned__extract_dow , subq_5.booking__ds_partitioned__extract_doy @@ -319,7 +301,6 @@ FULL OUTER JOIN ( , 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_week , subq_5.booking__paid_at__extract_day , subq_5.booking__paid_at__extract_dow , subq_5.booking__paid_at__extract_doy @@ -331,7 +312,6 @@ FULL OUTER JOIN ( , 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_week AS metric_time__extract_week , 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 @@ -362,7 +342,7 @@ FULL OUTER JOIN ( , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 , bookings_source_src_10001.is_instant - , bookings_source_src_10001.ds AS ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter @@ -370,11 +350,10 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter @@ -382,11 +361,10 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter @@ -394,12 +372,11 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy , bookings_source_src_10001.is_instant AS booking__is_instant - , bookings_source_src_10001.ds AS booking__ds__day + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter @@ -407,11 +384,10 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds) AS booking__ds__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy - , bookings_source_src_10001.ds_partitioned AS booking__ds_partitioned__day + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter @@ -419,11 +395,10 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(week FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_week , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy - , bookings_source_src_10001.paid_at AS booking__paid_at__day + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter @@ -431,9 +406,8 @@ FULL OUTER JOIN ( , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month - , EXTRACT(week FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_week , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dow FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy , bookings_source_src_10001.listing_id AS listing , bookings_source_src_10001.guest_id AS guest diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql index 0a8efb1bc9..873beed5f6 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql @@ -15,7 +15,7 @@ FROM ( -- Pass Only Elements: -- ['bookings', 'metric_time__day'] SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_12 @@ -30,11 +30,11 @@ FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - paid_at AS metric_time__day + DATE_TRUNC('day', paid_at) AS metric_time__day , SUM(booking_value) AS booking_payments FROM ***************************.fct_bookings bookings_source_src_10001 GROUP BY - paid_at + DATE_TRUNC('day', paid_at) ) subq_19 ON subq_14.metric_time__day = subq_19.metric_time__day diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql new file mode 100644 index 0000000000..fc804c3d2b --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql @@ -0,0 +1,441 @@ +-- Combine Metrics +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 +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_8.metric_time__day + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.booking_value + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_5 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql new file mode 100644 index 0000000000..552b4dc805 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Combine Metrics +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_value) AS booking_value +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_12 + GROUP BY + metric_time__day +) subq_14 +FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + DATE_TRUNC('day', ds) +) subq_19 +ON + subq_14.metric_time__day = subq_19.metric_time__day +GROUP BY + COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql new file mode 100644 index 0000000000..ce7231f3da --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql @@ -0,0 +1,135 @@ +-- Order By ['listing__country_latest'] Limit 100 +SELECT + subq_2.listing__country_latest +FROM ( + -- Pass Only Elements: + -- ['listing__country_latest'] + SELECT + subq_1.listing__country_latest + FROM ( + -- Constrain Output with WHERE + 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + WHERE listing__country_latest = 'us' + ) subq_1 + GROUP BY + subq_1.listing__country_latest +) subq_2 +ORDER BY subq_2.listing__country_latest DESC +LIMIT 100 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql new file mode 100644 index 0000000000..ec0d94dac2 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['listing__country_latest'] +-- Order By ['listing__country_latest'] Limit 100 +SELECT + listing__country_latest +FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_3 +WHERE listing__country_latest = 'us' +GROUP BY + listing__country_latest +ORDER BY listing__country_latest DESC +LIMIT 100 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql new file mode 100644 index 0000000000..c4110473ff --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant'] + SELECT + subq_8.is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.is_instant + , subq_7.listing__country_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing__country_latest'] + SELECT + subq_6.is_instant + , subq_6.listing__country_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.is_instant AS is_instant + , subq_5.country_latest AS listing__country_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_9.is_instant +) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql new file mode 100644 index 0000000000..29bb79a181 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql @@ -0,0 +1,35 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['bookings', 'is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing__country_latest'] + SELECT + subq_13.is_instant AS is_instant + , listings_latest_src_10004.country AS listing__country_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_13.listing = listings_latest_src_10004.listing_id +) subq_18 +WHERE listing__country_latest = 'us' +GROUP BY + is_instant diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql new file mode 100644 index 0000000000..82d0454072 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql @@ -0,0 +1,317 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__day + , subq_9.bookings AS family_bookings +FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_7.metric_time__day + , subq_7.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.metric_time__day + , subq_6.listing__capacity + , subq_6.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__capacity', 'metric_time__day'] + SELECT + subq_5.metric_time__day + , subq_5.listing__capacity + , subq_5.bookings + FROM ( + -- Join Standard Outputs + 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) 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_10017.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month + , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy + , listings_src_10017.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month + , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy + , listings_src_10017.country + , listings_src_10017.is_lux + , listings_src_10017.capacity + , listings_src_10017.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month + , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy + , listings_src_10017.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month + , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy + , listings_src_10017.country AS listing__country + , listings_src_10017.is_lux AS listing__is_lux + , listings_src_10017.capacity AS listing__capacity + , listings_src_10017.listing_id AS listing + , listings_src_10017.user_id AS user + , listings_src_10017.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10017 + ) subq_3 + ) subq_4 + ON + ( + 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_5 + ) subq_6 + WHERE listing__capacity > 2 + ) subq_7 + ) subq_8 + GROUP BY + subq_8.metric_time__day +) subq_9 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db1199fc2e --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql @@ -0,0 +1,47 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['bookings', 'metric_time__day'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + metric_time__day + , SUM(bookings) AS family_bookings +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_10017.capacity AS listing__capacity + , subq_12.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_12 + LEFT OUTER JOIN + ***************************.dim_listings listings_src_10017 + ON + ( + subq_12.listing = listings_src_10017.listing_id + ) AND ( + ( + subq_12.metric_time__day >= listings_src_10017.active_from + ) AND ( + ( + subq_12.metric_time__day < listings_src_10017.active_to + ) OR ( + listings_src_10017.active_to IS NULL + ) + ) + ) +) subq_16 +WHERE listing__capacity > 2 +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql new file mode 100644 index 0000000000..c1430d3764 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql @@ -0,0 +1,221 @@ +-- Order By [] Limit 1 +SELECT + subq_4.ds__day + , subq_4.bookings +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.ds__day + , subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_2.ds__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'ds__day'] + SELECT + subq_1.ds__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.ds__day + ) subq_3 +) subq_4 +LIMIT 1 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql new file mode 100644 index 0000000000..e52871ff7c --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql @@ -0,0 +1,19 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +-- Order By [] Limit 1 +SELECT + ds__day + , SUM(bookings) AS bookings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'ds__day'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_7 +GROUP BY + ds__day +LIMIT 1 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql new file mode 100644 index 0000000000..cf23763319 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql @@ -0,0 +1,151 @@ +-- Compute Metrics via Expressions +SELECT + subq_3.listing__country_latest + , subq_3.listings +FROM ( + -- Aggregate Measures + SELECT + subq_2.listing__country_latest + , SUM(subq_2.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings', 'listing__country_latest'] + SELECT + subq_1.listing__country_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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.listing__country_latest +) subq_3 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql new file mode 100644 index 0000000000..f7932552c3 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql @@ -0,0 +1,17 @@ +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(listings) AS listings +FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['listings', 'listing__country_latest'] + SELECT + country AS listing__country_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_6 +GROUP BY + listing__country_latest diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql new file mode 100644 index 0000000000..70ed3cd24c --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql @@ -0,0 +1,1012 @@ +-- Compute Metrics via Expressions +SELECT + subq_29.metric_time__day + , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , AVG(subq_9.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: + -- ['average_booking_value', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.average_booking_value + FROM ( + -- Pass Only Elements: + -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.listing__is_lux_latest + , subq_6.average_booking_value + FROM ( + -- Join Standard Outputs + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_9.metric_time__day + ) subq_10 + ) subq_11 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_22.metric_time__day + , subq_22.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_21.metric_time__day + , SUM(subq_21.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_20.metric_time__day + , subq_20.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_19.metric_time__day + , subq_19.listing__is_lux_latest + , subq_19.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_18.metric_time__day + , subq_18.listing__is_lux_latest + , subq_18.bookings + FROM ( + -- Join Standard Outputs + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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 + GROUP BY + subq_21.metric_time__day + ) subq_22 + ) subq_23 + ON + subq_11.metric_time__day = subq_23.metric_time__day + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_27.metric_time__day + , subq_27.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_26.metric_time__day + , SUM(subq_26.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + SELECT + subq_25.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_24 + ) subq_25 + ) subq_26 + GROUP BY + subq_26.metric_time__day + ) subq_27 + ) subq_28 + ON + COALESCE(subq_11.metric_time__day, subq_23.metric_time__day) = subq_28.metric_time__day + GROUP BY + COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..0b555b1430 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql @@ -0,0 +1,96 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr +FROM ( + -- Combine Metrics + SELECT + COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day) AS metric_time__day + , MAX(subq_41.average_booking_value) AS average_booking_value + , MAX(subq_53.bookings) AS bookings + , MAX(subq_58.booking_value) AS booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + DATE_TRUNC('day', bookings_source_src_10001.ds) AS metric_time__day + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , bookings_source_src_10001.booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id + ) subq_37 + WHERE listing__is_lux_latest + GROUP BY + metric_time__day + ) subq_41 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['bookings', 'listing__is_lux_latest', 'metric_time__day'] + SELECT + subq_44.metric_time__day AS metric_time__day + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , subq_44.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_44 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_10004 + ON + subq_44.listing = listings_latest_src_10004.listing_id + ) subq_49 + WHERE listing__is_lux_latest + GROUP BY + metric_time__day + ) subq_53 + ON + subq_41.metric_time__day = subq_53.metric_time__day + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_58 + ON + COALESCE(subq_41.metric_time__day, subq_53.metric_time__day) = subq_58.metric_time__day + GROUP BY + COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day) +) subq_59 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql new file mode 100644 index 0000000000..8504a01af1 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql @@ -0,0 +1,463 @@ +-- 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 +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_5.metric_time__day + , subq_5.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 + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_7 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + ) subq_10 + ) subq_11 + ON + subq_6.metric_time__day = subq_11.metric_time__day + GROUP BY + COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) +) subq_12 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql new file mode 100644 index 0000000000..77f5d693df --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -0,0 +1,53 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio +FROM ( + -- Combine Metrics + 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 + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(booking_value) AS booking_value_with_is_instant_constraint + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_15 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_19 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_24 + ON + subq_19.metric_time__day = subq_24.metric_time__day + GROUP BY + COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) +) subq_25 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql new file mode 100644 index 0000000000..f1e61da6cd --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -0,0 +1,236 @@ +-- Compute Metrics via Expressions +SELECT + subq_6.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 + FROM ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.booking__is_instant + , subq_2.bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE NOT booking__is_instant + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 +) subq_6 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql new file mode 100644 index 0000000000..18094198a4 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -0,0 +1,28 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , delayed_bookings * 2 AS double_counted_delayed_bookings +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS delayed_bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + WHERE NOT booking__is_instant + GROUP BY + metric_time__day +) subq_13 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql new file mode 100644 index 0000000000..91fcb63ee0 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -0,0 +1,368 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.listings, 0) AS DOUBLE) AS bookings_per_listing +FROM ( + -- Combine Metrics + SELECT + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_3.bookings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings'] + SELECT + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + ) subq_3 + ) subq_4 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_8.listings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_7.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings'] + SELECT + subq_6.listings + FROM ( + -- 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.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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_5 + ) subq_6 + ) subq_7 + ) subq_8 + ) subq_9 +) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql new file mode 100644 index 0000000000..8a1096e90f --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Combine Metrics +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 +) subq_15 +CROSS JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['listings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 +) subq_20 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql new file mode 100644 index 0000000000..6b26e02a73 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql @@ -0,0 +1,460 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.listing__user__home_state_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , subq_9.listing__user__home_state_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- 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 + FROM ( + -- Join Standard Outputs + 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.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'] + 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + 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_10017.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month + , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy + , listings_src_10017.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month + , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy + , listings_src_10017.country + , listings_src_10017.is_lux + , listings_src_10017.capacity + , listings_src_10017.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month + , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy + , listings_src_10017.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month + , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy + , listings_src_10017.country AS listing__country + , listings_src_10017.is_lux AS listing__is_lux + , listings_src_10017.capacity AS listing__capacity + , listings_src_10017.listing_id AS listing + , listings_src_10017.user_id AS user + , listings_src_10017.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10017 + ) 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_10021.ds) AS ds__day + , DATE_TRUNC('week', users_latest_src_10021.ds) AS ds__week + , DATE_TRUNC('month', users_latest_src_10021.ds) AS ds__month + , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS ds__quarter + , DATE_TRUNC('year', users_latest_src_10021.ds) AS ds__year + , EXTRACT(year FROM users_latest_src_10021.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10021.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10021.ds) AS ds__extract_month + , EXTRACT(day FROM users_latest_src_10021.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10021.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10021.ds) AS ds__extract_doy + , users_latest_src_10021.home_state_latest + , DATE_TRUNC('day', users_latest_src_10021.ds) AS user__ds__day + , DATE_TRUNC('week', users_latest_src_10021.ds) AS user__ds__week + , DATE_TRUNC('month', users_latest_src_10021.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_latest_src_10021.ds) AS user__ds__year + , EXTRACT(year FROM users_latest_src_10021.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10021.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10021.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_latest_src_10021.ds) AS user__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10021.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10021.ds) AS user__ds__extract_doy + , users_latest_src_10021.home_state_latest AS user__home_state_latest + , users_latest_src_10021.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10021 + ) subq_4 + ) subq_5 + ON + subq_3.user = subq_5.user + ) subq_6 + ) subq_7 + ON + ( + subq_2.listing = subq_7.listing + ) 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_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + , subq_9.listing__user__home_state_latest +) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..aa2ad14d34 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql @@ -0,0 +1,52 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['bookings', 'listing__user__home_state_latest', 'metric_time__day'] +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 +) subq_13 +LEFT OUTER JOIN ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + SELECT + listings_src_10017.active_from AS window_start__day + , listings_src_10017.active_to AS window_end__day + , listings_src_10017.listing_id AS listing + , users_latest_src_10021.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings listings_src_10017 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_10021 + ON + listings_src_10017.user_id = users_latest_src_10021.user_id +) subq_18 +ON + ( + subq_13.listing = subq_18.listing + ) AND ( + ( + subq_13.metric_time__day >= subq_18.window_start__day + ) AND ( + ( + subq_13.metric_time__day < subq_18.window_end__day + ) OR ( + subq_18.window_end__day IS NULL + ) + ) + ) +GROUP BY + subq_13.metric_time__day + , subq_18.user__home_state_latest diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql new file mode 100644 index 0000000000..2f8712914a --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql @@ -0,0 +1,440 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.listing__lux_listing__is_confirmed_lux + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , subq_9.listing__lux_listing__is_confirmed_lux + , SUM(subq_9.bookings) AS bookings + FROM ( + -- 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 + FROM ( + -- Join Standard Outputs + 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 + 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_10015.booking_value + , bookings_source_src_10015.guest_id AS bookers + , bookings_source_src_10015.booking_value AS average_booking_value + , bookings_source_src_10015.booking_value AS booking_payments + , bookings_source_src_10015.is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy + , bookings_source_src_10015.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10015.listing_id AS listing + , bookings_source_src_10015.guest_id AS guest + , bookings_source_src_10015.host_id AS host + , bookings_source_src_10015.guest_id AS user + , bookings_source_src_10015.listing_id AS booking__listing + , bookings_source_src_10015.guest_id AS booking__guest + , bookings_source_src_10015.host_id AS booking__host + , bookings_source_src_10015.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10015 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['lux_listing__is_confirmed_lux', + -- 'lux_listing__window_start__day', + -- 'lux_listing__window_end__day', + -- '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_10018.listing_id AS listing + , lux_listing_mapping_src_10018.lux_listing_id AS lux_listing + , lux_listing_mapping_src_10018.lux_listing_id AS listing__lux_listing + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + ) 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_10019.valid_from AS window_start__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS window_start__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS window_start__year + , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS window_start__extract_month + , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_from) AS window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS window_start__extract_doy + , lux_listings_src_10019.valid_to AS window_end__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS window_end__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS window_end__year + , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS window_end__extract_month + , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_to) AS window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS window_end__extract_doy + , lux_listings_src_10019.is_confirmed_lux + , lux_listings_src_10019.valid_from AS lux_listing__window_start__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS lux_listing__window_start__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS lux_listing__window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS lux_listing__window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS lux_listing__window_start__year + , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_month + , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_doy + , lux_listings_src_10019.valid_to AS lux_listing__window_end__day + , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS lux_listing__window_end__week + , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS lux_listing__window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS lux_listing__window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS lux_listing__window_end__year + , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_month + , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_doy + , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux + , lux_listings_src_10019.lux_listing_id AS lux_listing + FROM ***************************.dim_lux_listings lux_listings_src_10019 + ) subq_4 + ) subq_5 + ON + subq_3.lux_listing = subq_5.lux_listing + ) subq_6 + ) subq_7 + ON + ( + subq_2.listing = subq_7.listing + ) 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_8 + ) subq_9 + GROUP BY + subq_9.metric_time__day + , subq_9.listing__lux_listing__is_confirmed_lux +) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..add7e259ab --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql @@ -0,0 +1,55 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['bookings', 'listing__lux_listing__is_confirmed_lux', 'metric_time__day'] +-- 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 +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day', 'listing'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , listing_id AS listing + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10015 +) subq_13 +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_10019.valid_from AS lux_listing__window_start__day + , lux_listings_src_10019.valid_to AS lux_listing__window_end__day + , lux_listing_mapping_src_10018.listing_id AS listing + , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + LEFT OUTER JOIN + ***************************.dim_lux_listings lux_listings_src_10019 + ON + lux_listing_mapping_src_10018.lux_listing_id = lux_listings_src_10019.lux_listing_id +) subq_18 +ON + ( + subq_13.listing = subq_18.listing + ) AND ( + ( + subq_13.metric_time__day >= subq_18.lux_listing__window_start__day + ) AND ( + ( + subq_13.metric_time__day < subq_18.lux_listing__window_end__day + ) OR ( + subq_18.lux_listing__window_end__day IS NULL + ) + ) + ) +GROUP BY + subq_13.metric_time__day + , subq_18.lux_listing__is_confirmed_lux diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql new file mode 100644 index 0000000000..f07aa049e6 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql @@ -0,0 +1,366 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.account_id__customer_id__customer_name + , subq_10.txn_count +FROM ( + -- Aggregate Measures + SELECT + subq_9.account_id__customer_id__customer_name + , SUM(subq_9.txn_count) AS txn_count + FROM ( + -- Pass Only Elements: + -- ['txn_count', 'account_id__customer_id__customer_name'] + SELECT + subq_8.account_id__customer_id__customer_name + , subq_8.txn_count + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds_partitioned__day AS ds_partitioned__day + , subq_7.ds_partitioned__day AS account_id__ds_partitioned__day + , subq_2.account_id AS account_id + , subq_7.customer_id__customer_name AS account_id__customer_id__customer_name + , subq_2.txn_count AS txn_count + FROM ( + -- Pass Only Elements: + -- ['txn_count', 'ds_partitioned__day', 'account_id'] + SELECT + subq_1.ds_partitioned__day + , subq_1.account_id + , subq_1.txn_count + FROM ( + -- Metric Time Dimension 'ds' + 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_10010.txn_count + , DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_10010.ds) AS ds__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS ds__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS ds__year + , EXTRACT(year FROM account_month_txns_src_10010.ds) AS ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds) AS ds__extract_month + , EXTRACT(day FROM account_month_txns_src_10010.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds) AS ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS ds__extract_doy + , account_month_txns_src_10010.account_month + , DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_10010.ds) AS account_id__ds__day + , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS account_id__ds__week + , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS account_id__ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS account_id__ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS account_id__ds__year + , EXTRACT(year FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_month + , EXTRACT(day FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_doy + , account_month_txns_src_10010.account_month AS account_id__account_month + , account_month_txns_src_10010.account_id + FROM ***************************.account_month_txns account_month_txns_src_10010 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] + SELECT + subq_6.ds_partitioned__day + , subq_6.account_id + , subq_6.customer_id__customer_name + FROM ( + -- Join Standard Outputs + SELECT + subq_3.ds_partitioned__day AS ds_partitioned__day + , subq_3.ds_partitioned__week AS ds_partitioned__week + , subq_3.ds_partitioned__month AS ds_partitioned__month + , subq_3.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_3.ds_partitioned__year AS ds_partitioned__year + , subq_3.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_3.account_id__ds_partitioned__day AS account_id__ds_partitioned__day + , subq_3.account_id__ds_partitioned__week AS account_id__ds_partitioned__week + , subq_3.account_id__ds_partitioned__month AS account_id__ds_partitioned__month + , subq_3.account_id__ds_partitioned__quarter AS account_id__ds_partitioned__quarter + , subq_3.account_id__ds_partitioned__year AS account_id__ds_partitioned__year + , subq_3.account_id__ds_partitioned__extract_year AS account_id__ds_partitioned__extract_year + , subq_3.account_id__ds_partitioned__extract_quarter AS account_id__ds_partitioned__extract_quarter + , subq_3.account_id__ds_partitioned__extract_month AS account_id__ds_partitioned__extract_month + , subq_3.account_id__ds_partitioned__extract_day AS account_id__ds_partitioned__extract_day + , subq_3.account_id__ds_partitioned__extract_dow AS account_id__ds_partitioned__extract_dow + , subq_3.account_id__ds_partitioned__extract_doy AS account_id__ds_partitioned__extract_doy + , subq_3.bridge_account__ds_partitioned__day AS bridge_account__ds_partitioned__day + , subq_3.bridge_account__ds_partitioned__week AS bridge_account__ds_partitioned__week + , subq_3.bridge_account__ds_partitioned__month AS bridge_account__ds_partitioned__month + , subq_3.bridge_account__ds_partitioned__quarter AS bridge_account__ds_partitioned__quarter + , subq_3.bridge_account__ds_partitioned__year AS bridge_account__ds_partitioned__year + , subq_3.bridge_account__ds_partitioned__extract_year AS bridge_account__ds_partitioned__extract_year + , subq_3.bridge_account__ds_partitioned__extract_quarter AS bridge_account__ds_partitioned__extract_quarter + , subq_3.bridge_account__ds_partitioned__extract_month AS bridge_account__ds_partitioned__extract_month + , subq_3.bridge_account__ds_partitioned__extract_day AS bridge_account__ds_partitioned__extract_day + , subq_3.bridge_account__ds_partitioned__extract_dow AS bridge_account__ds_partitioned__extract_dow + , subq_3.bridge_account__ds_partitioned__extract_doy AS bridge_account__ds_partitioned__extract_doy + , subq_5.ds_partitioned__day AS customer_id__ds_partitioned__day + , subq_5.ds_partitioned__week AS customer_id__ds_partitioned__week + , subq_5.ds_partitioned__month AS customer_id__ds_partitioned__month + , subq_5.ds_partitioned__quarter AS customer_id__ds_partitioned__quarter + , subq_5.ds_partitioned__year AS customer_id__ds_partitioned__year + , subq_5.ds_partitioned__extract_year AS customer_id__ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter AS customer_id__ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month AS customer_id__ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day AS customer_id__ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow AS customer_id__ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy AS customer_id__ds_partitioned__extract_doy + , subq_3.account_id AS account_id + , subq_3.customer_id AS customer_id + , subq_3.account_id__customer_id AS account_id__customer_id + , subq_3.bridge_account__account_id AS bridge_account__account_id + , subq_3.bridge_account__customer_id AS bridge_account__customer_id + , subq_3.extra_dim AS extra_dim + , subq_3.account_id__extra_dim AS account_id__extra_dim + , subq_3.bridge_account__extra_dim AS bridge_account__extra_dim + , subq_5.customer_name AS customer_id__customer_name + , subq_5.customer_atomic_weight AS customer_id__customer_atomic_weight + FROM ( + -- Read Elements From Semantic Model 'bridge_table' + SELECT + bridge_table_src_10011.extra_dim + , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_doy + , bridge_table_src_10011.extra_dim AS account_id__extra_dim + , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , bridge_table_src_10011.extra_dim AS bridge_account__extra_dim + , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy + , bridge_table_src_10011.account_id + , bridge_table_src_10011.customer_id + , bridge_table_src_10011.customer_id AS account_id__customer_id + , bridge_table_src_10011.account_id AS bridge_account__account_id + , bridge_table_src_10011.customer_id AS bridge_account__customer_id + FROM ***************************.bridge_table bridge_table_src_10011 + ) subq_3 + 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', + -- 'customer_id'] + 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.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.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 ( + -- Read Elements From Semantic Model 'customer_table' + SELECT + customer_table_src_10013.customer_name + , customer_table_src_10013.customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_doy + , customer_table_src_10013.customer_name AS customer_id__customer_name + , customer_table_src_10013.customer_atomic_weight AS customer_id__customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_doy + , customer_table_src_10013.customer_id + FROM ***************************.customer_table customer_table_src_10013 + ) subq_4 + ) subq_5 + ON + ( + subq_3.customer_id = subq_5.customer_id + ) AND ( + subq_3.ds_partitioned__day = subq_5.ds_partitioned__day + ) + ) subq_6 + ) subq_7 + ON + ( + subq_2.account_id = subq_7.account_id + ) AND ( + subq_2.ds_partitioned__day = subq_7.ds_partitioned__day + ) + ) subq_8 + ) subq_9 + GROUP BY + subq_9.account_id__customer_id__customer_name +) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql new file mode 100644 index 0000000000..8a42052413 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql @@ -0,0 +1,35 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['txn_count', 'account_id__customer_id__customer_name'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + subq_18.customer_id__customer_name AS account_id__customer_id__customer_name + , SUM(account_month_txns_src_10010.txn_count) AS txn_count +FROM ***************************.account_month_txns account_month_txns_src_10010 +LEFT OUTER JOIN ( + -- Join Standard Outputs + -- Pass Only Elements: + -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] + SELECT + DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__day + , bridge_table_src_10011.account_id AS account_id + , customer_table_src_10013.customer_name AS customer_id__customer_name + FROM ***************************.bridge_table bridge_table_src_10011 + LEFT OUTER JOIN + ***************************.customer_table customer_table_src_10013 + ON + ( + bridge_table_src_10011.customer_id = customer_table_src_10013.customer_id + ) AND ( + DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) = DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) + ) +) subq_18 +ON + ( + account_month_txns_src_10010.account_id = subq_18.account_id + ) AND ( + DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) = subq_18.ds_partitioned__day + ) +GROUP BY + subq_18.customer_id__customer_name diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql new file mode 100644 index 0000000000..6231b02dc1 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql @@ -0,0 +1,538 @@ +-- Combine Metrics +SELECT + MAX(subq_5.bookings) AS bookings + , MAX(subq_11.listings) AS listings +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_4.bookings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_3.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings'] + SELECT + subq_2.bookings + FROM ( + -- Constrain Time Range to [2020-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.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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' + ) subq_2 + ) subq_3 + ) subq_4 +) subq_5 +CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_10.listings + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_9.listings) AS listings + FROM ( + -- Pass Only Elements: + -- ['listings'] + SELECT + subq_8.listings + FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + 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 + 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_6 + ) subq_7 + WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' + ) subq_8 + ) subq_9 + ) subq_10 +) subq_11 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql new file mode 100644 index 0000000000..5ed649f283 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql @@ -0,0 +1,30 @@ +-- Combine Metrics +SELECT + MAX(subq_17.bookings) AS bookings + , MAX(subq_23.listings) AS listings +FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- Pass Only Elements: + -- ['bookings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' +) subq_17 +CROSS JOIN ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- Pass Only Elements: + -- ['listings'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(1) AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10004 + WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' +) subq_23 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql new file mode 100644 index 0000000000..8b9f457552 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql @@ -0,0 +1,244 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.user__home_state + , subq_7.identity_verifications +FROM ( + -- Aggregate Measures + SELECT + subq_6.user__home_state + , SUM(subq_6.identity_verifications) AS identity_verifications + FROM ( + -- Pass Only Elements: + -- ['identity_verifications', 'user__home_state'] + SELECT + subq_5.user__home_state + , subq_5.identity_verifications + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds_partitioned__day AS ds_partitioned__day + , subq_4.ds_partitioned__day AS user__ds_partitioned__day + , subq_2.user AS user + , subq_4.home_state AS user__home_state + , subq_2.identity_verifications AS identity_verifications + FROM ( + -- Pass Only Elements: + -- ['identity_verifications', 'ds_partitioned__day', 'user'] + 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_10003.ds) AS ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month + , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type + , DATE_TRUNC('day', id_verifications_src_10003.ds) AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month + , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_10003.verification_type AS verification__verification_type + , id_verifications_src_10003.verification_id AS verification + , id_verifications_src_10003.user_id AS user + , id_verifications_src_10003.user_id AS verification__user + FROM ***************************.fct_id_verifications id_verifications_src_10003 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state', 'ds_partitioned__day', 'user'] + SELECT + subq_3.ds_partitioned__day + , subq_3.user + , subq_3.home_state + FROM ( + -- Read Elements From Semantic Model 'users_ds_source' + SELECT + DATE_TRUNC('day', users_ds_source_src_10007.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_10007.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10007.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_10007.home_state + , DATE_TRUNC('day', users_ds_source_src_10007.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_10007.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.ds) AS user__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10007.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_10007.home_state AS user__home_state + , users_ds_source_src_10007.user_id AS user + FROM ***************************.dim_users users_ds_source_src_10007 + ) subq_3 + ) subq_4 + ON + ( + subq_2.user = subq_4.user + ) AND ( + subq_2.ds_partitioned__day = subq_4.ds_partitioned__day + ) + ) subq_5 + ) subq_6 + GROUP BY + subq_6.user__home_state +) subq_7 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql new file mode 100644 index 0000000000..c15982d861 --- /dev/null +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql @@ -0,0 +1,29 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['identity_verifications', 'user__home_state'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + users_ds_source_src_10007.home_state AS user__home_state + , SUM(subq_10.identity_verifications) AS identity_verifications +FROM ( + -- Read Elements From Semantic Model 'id_verifications' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['identity_verifications', 'ds_partitioned__day', 'user'] + SELECT + DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day + , user_id AS user + , 1 AS identity_verifications + FROM ***************************.fct_id_verifications id_verifications_src_10003 +) subq_10 +LEFT OUTER JOIN + ***************************.dim_users users_ds_source_src_10007 +ON + ( + subq_10.user = users_ds_source_src_10007.user_id + ) AND ( + subq_10.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) + ) +GROUP BY + users_ds_source_src_10007.home_state diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql index c7949f8a59..a3bb3c8e79 100644 --- a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql +++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql @@ -9,7 +9,7 @@ FROM ( -- Pass Only Elements: -- ['bookings', 'metric_time__day'] SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql index 701465ead6..584414321a 100644 --- a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql +++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql @@ -10,7 +10,7 @@ CREATE TABLE ***************************.test_table AS ( -- Pass Only Elements: -- ['bookings', 'metric_time__day'] SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql new file mode 100644 index 0000000000..250642f628 --- /dev/null +++ b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql @@ -0,0 +1,228 @@ +-- Compute Metrics via Expressions +SELECT + subq_6.metric_time__day + , subq_6.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 + FROM ( + -- Date Spine + SELECT + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ON + subq_4.metric_time__day = subq_3.metric_time__day +) subq_6 diff --git a/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql new file mode 100644 index 0000000000..cc3c93f375 --- /dev/null +++ b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- 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 +LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + GROUP BY + metric_time__day +) subq_10 +ON + subq_12.ds = subq_10.metric_time__day From b54e03b22f8f74c1570c9ea513a43478302c614d Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 12:53:40 -0700 Subject: [PATCH 10/18] Fix additional test case snapshots related to extract function --- .../test_dimensions_requiring_join__plan0.sql | 169 ++++++++++++++++++ ...nsions_requiring_join__plan0_optimized.sql | 14 ++ ...nth_dimension_and_offset_window__plan0.sql | 100 +++++++++++ ...ion_and_offset_window__plan0_optimized.sql | 28 +++ 4 files changed, 311 insertions(+) create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql new file mode 100644 index 0000000000..acae28a7e4 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql @@ -0,0 +1,169 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_3.listing__is_lux_latest + , subq_3.user__home_state_latest +FROM ( + -- Join Standard Outputs + 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_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) 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_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user +) subq_3 +GROUP BY + subq_3.listing__is_lux_latest + , subq_3.user__home_state_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql new file mode 100644 index 0000000000..4bf3539984 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest +FROM ***************************.dim_listings_latest listings_latest_src_10004 +FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 +ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +GROUP BY + listings_latest_src_10004.is_lux + , users_latest_src_10008.home_state_latest diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql new file mode 100644 index 0000000000..5c7900db95 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -0,0 +1,100 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__month + , SUM(subq_5.bookings_monthly) AS bookings_monthly + FROM ( + -- Pass Only Elements: + -- ['bookings_monthly', 'metric_time__month'] + SELECT + subq_4.metric_time__month + , subq_4.bookings_monthly + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__month AS metric_time__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 + FROM ( + -- Date 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' + 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_10024.bookings_monthly + , DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_month + , DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_month + , bookings_monthly_source_src_10024.listing_id AS listing + , bookings_monthly_source_src_10024.listing_id AS booking__listing + FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__month) = subq_1.metric_time__month + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__month + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql new file mode 100644 index 0000000000..996946d661 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -0,0 +1,28 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_last_month AS bookings_last_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings_monthly', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__month AS metric_time__month + , SUM(bookings_monthly_source_src_10024.bookings_monthly) AS bookings_last_month + FROM ( + -- Date Spine + SELECT + DATE_TRUNC('month', ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('month', ds) + ) subq_10 + INNER JOIN + ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 + ON + DATE_TRUNC('month', subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) + GROUP BY + subq_10.metric_time__month +) subq_15 From 949f3d1a1812681fef500da8a995a3635d385ecf Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 15:59:42 -0700 Subject: [PATCH 11/18] Use positional arguments in group by to fix tests --- .../test_cases/itest_cumulative_metric.yaml | 4 ++-- .../integration/test_cases/itest_metrics.yaml | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml b/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml index 67b4315b2b..a86a9ea838 100644 --- a/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml +++ b/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml @@ -325,8 +325,8 @@ integration_test: group_bys: ["metric_time__day"] order_bys: ["metric_time__day"] where_filter: | - {{ render_time_dimension_template('metric_time', 'day') }} = '2019-12-20' - or {{ render_time_dimension_template('metric_time', 'day') }} = '2020-01-04' + {{ render_time_dimension_template('metric_time', 'day') }} = {{ cast_to_ts('2019-12-20') }} + or {{ render_time_dimension_template('metric_time', 'day') }} = {{ cast_to_ts('2020-01-04') }} check_query: | SELECT COUNT (DISTINCT(b.guest_id)) as every_two_days_bookers diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index 89c3b9d33e..67e33cf2ee 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -1151,7 +1151,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY metric_time__day + GROUP BY 1 ) subq_3 ON subq_5.ds = subq_3.metric_time__day --- @@ -1169,14 +1169,14 @@ integration_test: SELECT {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month FROM {{ source_schema }}.mf_time_spine subq_5 - GROUP BY metric_time__month + GROUP BY 1 ) subq_4 LEFT OUTER JOIN ( SELECT {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY metric_time__month + GROUP BY 1 ) subq_3 ON subq_4.metric_time__month = subq_3.metric_time__month --- @@ -1192,7 +1192,7 @@ integration_test: , COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0 FROM {{ source_schema }}.fct_bookings bookings_source_src_1 GROUP BY - booking__paid_at__day + 1 --- integration_test: name: simple_fill_nulls_with_0_with_categorical_dimension @@ -1205,7 +1205,7 @@ integration_test: is_instant AS booking__is_instant , COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0 FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY booking__is_instant + GROUP BY 1 --- integration_test: name: simple_join_to_time_spine @@ -1224,7 +1224,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 GROUP BY - metric_time__day + 1 ) subq_3 ON subq_5.ds = subq_3.metric_time__day @@ -1240,7 +1240,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day , COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0_without_time_spine FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY metric_time__day + GROUP BY 1 --- integration_test: name: cumulative_fill_nulls @@ -1293,7 +1293,7 @@ integration_test: , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 GROUP BY - metric_time__day + 1 ) subq_3 ON subq_5.ds = subq_3.metric_time__day ) subq_7 @@ -1336,7 +1336,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY metric_time__day + GROUP BY 1 ) subq_3 ON subq_5.ds = subq_3.metric_time__day ) subq_7 @@ -1345,7 +1345,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day , SUM(1) AS views FROM {{ source_schema }}.fct_views views_source_src_9 - GROUP BY metric_time__day + GROUP BY 1 ) subq_12 ON subq_7.metric_time__day = subq_12.metric_time__day GROUP BY COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) @@ -1384,7 +1384,7 @@ integration_test: {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day , SUM(1) AS bookings FROM {{ source_schema }}.fct_bookings bookings_source_src_1 - GROUP BY metric_time__day + GROUP BY 1 ) subq_3 ON subq_5.ds = subq_3.metric_time__day ) subq_6 From bfd1414181b61cb6aa9410fc0723840e454616de Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 16:50:29 -0700 Subject: [PATCH 12/18] Fix time delta expression for Trino and regenerate snapshot --- metricflow/sql/render/trino.py | 6 ------ ...lative_metric_with_non_adjustable_time_filter__plan0.sql | 2 +- ...ric_with_non_adjustable_time_filter__plan0_optimized.sql | 2 +- .../test_cumulative_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_metric_with_time_constraint__plan0_optimized.sql | 2 +- ...st_join_to_time_spine_node_with_offset_window__plan0.sql | 2 +- ..._time_spine_node_with_offset_window__plan0_optimized.sql | 2 +- ...metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- ...h_month_dimension_and_offset_window__plan0_optimized.sql | 2 +- .../Trino/test_derived_metric_with_offset_window__plan0.sql | 2 +- ...t_derived_metric_with_offset_window__plan0_optimized.sql | 2 +- ...ved_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ..._with_offset_window_and_granularity__plan0_optimized.sql | 2 +- ...metric_with_offset_window_and_offset_to_grain__plan0.sql | 2 +- ...h_offset_window_and_offset_to_grain__plan0_optimized.sql | 2 +- ...et_window_and_offset_to_grain_and_granularity__plan0.sql | 2 +- ...and_offset_to_grain_and_granularity__plan0_optimized.sql | 2 +- ...ved_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- ..._with_offset_window_and_time_filter__plan0_optimized.sql | 2 +- .../Trino/test_derived_offset_cumulative_metric__plan0.sql | 4 ++-- ...st_derived_offset_cumulative_metric__plan0_optimized.sql | 4 ++-- ...t_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...offset_metric_with_one_input_metric__plan0_optimized.sql | 2 +- .../Trino/test_cumulative_fill_nulls__plan0.sql | 2 +- .../Trino/test_cumulative_fill_nulls__plan0_optimized.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- ...ved_fill_nulls_for_one_input_metric__plan0_optimized.sql | 2 +- .../Trino/test_offset_window_with_date_part__plan0.sql | 2 +- .../test_offset_window_with_date_part__plan0_optimized.sql | 2 +- 29 files changed, 30 insertions(+), 36 deletions(-) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 590370a59b..4a3d4bf71f 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -46,12 +46,6 @@ def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlE """Render time delta for Trino, require granularity in quotes and function name change.""" arg_rendered = node.arg.accept(self) - if node.granularity: - return SqlExpressionRenderResult( - sql=f"DATE_TRUNC('{node.granularity.value}', {arg_rendered.sql})", - bind_parameters=arg_rendered.bind_parameters, - ) - count = node.count granularity = node.granularity if granularity == TimeGranularity.QUARTER: diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql index 19ade80c3b..28bc3ef177 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql @@ -324,7 +324,7 @@ FROM ( ( subq_1.metric_time__day <= subq_2.metric_time__day ) AND ( - subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day) ) ) subq_4 ) subq_5 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql index c71bac4a78..3e52c58c9f 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql @@ -18,7 +18,7 @@ FROM ( ( DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_11.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_11.ds) + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_11.ds) ) ) subq_13 WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql index bbb92b55c8..aab524ac8b 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql @@ -179,7 +179,7 @@ FROM ( ( subq_2.metric_time__day <= subq_3.metric_time__day ) AND ( - subq_2.metric_time__day > DATE_TRUNC('month', subq_3.metric_time__day) + subq_2.metric_time__day > DATE_ADD('month', -2, subq_3.metric_time__day) ) ) subq_5 ) subq_6 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql index e89c6158e9..df4cc42b14 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -29,7 +29,7 @@ ON ( subq_11.metric_time__day <= subq_12.metric_time__day ) AND ( - subq_11.metric_time__day > DATE_TRUNC('month', subq_12.metric_time__day) + subq_11.metric_time__day > DATE_ADD('month', -2, subq_12.metric_time__day) ) WHERE subq_11.metric_time__month BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' GROUP BY diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql index 6010e91d29..520a9c82e5 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -231,4 +231,4 @@ INNER JOIN ( ) subq_3 ) subq_4 ON - DATE_TRUNC('day', subq_5.metric_time__day) = subq_4.metric_time__day + DATE_ADD('day', -10, subq_5.metric_time__day) = subq_4.metric_time__day diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql index 603f3c1ac2..1a6479ac03 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -33,4 +33,4 @@ INNER JOIN ( ) subq_10 ) subq_11 ON - DATE_TRUNC('day', subq_12.metric_time__day) = subq_11.metric_time__day + DATE_ADD('day', -10, subq_12.metric_time__day) = subq_11.metric_time__day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 5c7900db95..69afbb9475 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -91,7 +91,7 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__month) = subq_1.metric_time__month + DATE_ADD('month', -1, subq_2.metric_time__month) = subq_1.metric_time__month ) subq_4 ) subq_5 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 996946d661..dfd07817f3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -22,7 +22,7 @@ FROM ( INNER JOIN ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 ON - DATE_TRUNC('month', subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) + DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) GROUP BY subq_10.metric_time__month ) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index 14c9ec1451..10760992bd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -533,7 +533,7 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql index e4680b0c3b..7ad5604b52 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day GROUP BY subq_22.ds ) subq_26 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 696061840e..89b794993f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -533,7 +533,7 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index e45ac7276d..d272b406e6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day GROUP BY DATE_TRUNC('quarter', subq_22.ds) ) subq_26 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 7fd3f09a14..c678d364d3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -633,7 +633,7 @@ FROM ( ) subq_8 ) subq_9 ON - DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day + DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day ) subq_12 ) subq_13 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 126a2a6467..74be8a4d15 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -50,7 +50,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_26 ON - DATE_TRUNC('month', subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day GROUP BY subq_28.ds ) subq_32 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 87d0d91c22..0a7185d41a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -634,7 +634,7 @@ FROM ( ) subq_8 ) subq_9 ON - DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day + DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day ) subq_12 ) subq_13 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 80083c008d..9104a34910 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -51,7 +51,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_26 ON - DATE_TRUNC('month', subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day GROUP BY DATE_TRUNC('year', subq_28.ds) ) subq_32 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index a1e0e15156..a4af805358 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -545,7 +545,7 @@ FROM ( ) subq_6 ) subq_7 ON - DATE_TRUNC('day', subq_8.metric_time__day) = subq_7.metric_time__day + DATE_ADD('day', -14, subq_8.metric_time__day) = subq_7.metric_time__day ) subq_10 ) subq_11 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 1b158e1887..9d5acb0380 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -53,7 +53,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_23 ON - DATE_TRUNC('day', subq_25.ds) = subq_23.metric_time__day + DATE_ADD('day', -14, subq_25.ds) = subq_23.metric_time__day ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index cdd0f927f5..cdc607f869 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -421,11 +421,11 @@ FROM ( ( subq_1.metric_time__day <= subq_2.metric_time__day ) AND ( - subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day) ) ) subq_4 ON - DATE_TRUNC('day', subq_5.metric_time__day) = subq_4.metric_time__day + DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day ) subq_7 ) subq_8 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql index ac6ff46f0c..9d0f96b918 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -24,11 +24,11 @@ FROM ( ( DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_14.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_14.ds) + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_14.ds) ) ) subq_15 ON - DATE_TRUNC('day', subq_17.ds) = subq_15.metric_time__day + DATE_ADD('day', -2, subq_17.ds) = subq_15.metric_time__day GROUP BY subq_17.ds ) subq_21 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index b3e657945d..b6365b4353 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -311,7 +311,7 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('day', subq_2.metric_time__day) = subq_1.metric_time__day + DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day ) subq_4 ) subq_5 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 29d6978951..5b1b77974b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -21,7 +21,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_9 ON - DATE_TRUNC('day', subq_11.ds) = subq_9.metric_time__day + DATE_ADD('day', -5, subq_11.ds) = subq_9.metric_time__day GROUP BY subq_11.ds ) subq_15 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql index 3a7aa46753..69b679c136 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql @@ -330,7 +330,7 @@ FROM ( ( subq_1.metric_time__day <= subq_2.metric_time__day ) AND ( - subq_1.metric_time__day > DATE_TRUNC('day', subq_2.metric_time__day) + subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day) ) ) subq_4 ) subq_5 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql index 9d7a4e4446..46495e1c9e 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql @@ -23,7 +23,7 @@ FROM ( ( DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_13.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_TRUNC('day', subq_13.ds) + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_13.ds) ) GROUP BY subq_13.ds diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index a8b1eb779c..245d744540 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -547,7 +547,7 @@ FROM ( ) subq_8 ) subq_9 ON - DATE_TRUNC('day', subq_10.metric_time__day) = subq_9.metric_time__day + DATE_ADD('day', -14, subq_10.metric_time__day) = subq_9.metric_time__day ) subq_12 ) subq_13 GROUP BY diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 1178cac9b1..b60ff25331 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -60,7 +60,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_26 ON - DATE_TRUNC('day', subq_28.ds) = subq_26.metric_time__day + DATE_ADD('day', -14, subq_28.ds) = subq_26.metric_time__day GROUP BY subq_28.ds ) subq_32 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 68af4ecdc9..7fd3032459 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -533,7 +533,7 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('day', subq_7.metric_time__day) = subq_6.metric_time__day + DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql index 5dcc27cbef..3a967f282f 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql @@ -46,7 +46,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_20 ON - DATE_TRUNC('day', subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day GROUP BY EXTRACT(DAY_OF_WEEK FROM subq_22.ds) ) subq_26 From 00dc02664411c2e3329dc01e8bddcf1f78aeea2d Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Tue, 14 Nov 2023 17:12:47 -0700 Subject: [PATCH 13/18] Add trino to cd-sql-engine-tests --- pyproject.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5ad45c6689..fa6b3f30e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -189,8 +189,9 @@ features = [ ] [tool.hatch.envs.trino-env.env-vars] -MF_TEST_ADAPTER_TYPE="trino" -MF_SQL_ENGINE_URL="trino://trino@localhost:8080/" +MF_TEST_ADAPTER_TYPE = "trino" +MF_SQL_ENGINE_URL = "trino://trino@localhost:8080/" +DBT_ENV_SECRET_CATALOG="memory" [tool.hatch.envs.trino-env] description = "Dev environment for working with the Trino adapter" From f4df9fa3dbbd7f7b3d5e47a3935b32519b589915 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Wed, 22 Nov 2023 14:43:29 -0700 Subject: [PATCH 14/18] Address function inline comments --- metricflow/test/integration/test_configured_cases.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/metricflow/test/integration/test_configured_cases.py b/metricflow/test/integration/test_configured_cases.py index 32a78f79fe..dcf6722d8b 100644 --- a/metricflow/test/integration/test_configured_cases.py +++ b/metricflow/test/integration/test_configured_cases.py @@ -77,7 +77,12 @@ def render_between_time_constraint( start_time: str, stop_time: str, ) -> str: - """Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'" since Trino require timestamp literals to be wrapped in a timestamp() function.""" + """Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'". + + This will cast the literals as needed for each engine, and provide an alternative to incrementing + the date as we do in render_time_constraint. Using BETWEEN is more robust for cases involving potentially + mixed granularities. + """ start_expr = self.cast_to_ts(f"{start_time}") stop_expr = self.cast_to_ts(f"{stop_time}") return f"{expr} BETWEEN {start_expr} AND {stop_expr}" From c9d7229c0d558da7c4d94b284919610148d9a749 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Wed, 22 Nov 2023 16:14:39 -0700 Subject: [PATCH 15/18] bump version for dependencies --- dbt-metricflow/pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt-metricflow/pyproject.toml b/dbt-metricflow/pyproject.toml index eb1a71794f..c938fcebd8 100644 --- a/dbt-metricflow/pyproject.toml +++ b/dbt-metricflow/pyproject.toml @@ -51,7 +51,7 @@ snowflake = [ "dbt-snowflake~=1.7.0" ] trino = [ - "dbt-trino~=1.6.0" + "dbt-trino~=1.7.0" ] [tool.hatch.build.targets.sdist] @@ -63,4 +63,4 @@ exclude = [ ".pre-commit-config.yaml", "CONTRIBUTING.md", "MAKEFILE", -] +] \ No newline at end of file From 603419921270d936ea2f8f73fcff00d8ab6bb007 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sat, 16 Dec 2023 10:26:09 -0700 Subject: [PATCH 16/18] Fix test cases for trino related to ts scalar expression --- .../test_cases/itest_constraints.yaml | 4 +- .../integration/test_cases/itest_metrics.yaml | 2 +- ...nversion_count_with_no_group_by__plan0.sql | 346 +++++++++++++ ...ount_with_no_group_by__plan0_optimized.sql | 63 +++ .../Trino/test_conversion_rate__plan0.sql | 355 +++++++++++++ .../test_conversion_rate__plan0_optimized.sql | 83 +++ ...n_rate_with_constant_properties__plan0.sql | 389 ++++++++++++++ ...h_constant_properties__plan0_optimized.sql | 111 ++++ ...onversion_rate_with_no_group_by__plan0.sql | 346 +++++++++++++ ...rate_with_no_group_by__plan0_optimized.sql | 63 +++ ...est_conversion_rate_with_window__plan0.sql | 379 ++++++++++++++ ...sion_rate_with_window__plan0_optimized.sql | 101 ++++ ...st_convert_query_semantic_model__plan0.sql | 52 +- ...le_semantic_model_with_measures__plan0.sql | 100 ++-- ...semantic_model_without_measures__plan0.sql | 52 +- .../Trino/test_cumulative_metric__plan0.sql | 52 +- ...est_cumulative_metric__plan0_optimized.sql | 2 +- ...cumulative_metric_grain_to_date__plan0.sql | 52 +- ..._metric_grain_to_date__plan0_optimized.sql | 2 +- .../test_cumulative_metric_no_ds__plan0.sql | 52 +- ...mulative_metric_no_ds__plan0_optimized.sql | 2 +- ...est_cumulative_metric_no_window__plan0.sql | 52 +- ...tive_metric_no_window__plan0_optimized.sql | 2 +- ..._no_window_with_time_constraint__plan0.sql | 52 +- ..._with_time_constraint__plan0_optimized.sql | 2 +- ...ive_metric_with_time_constraint__plan0.sql | 56 +-- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../test_combined_metrics_plan__ep_0.xml | 2 +- .../Trino/test_joined_plan__ep_0.xml | 8 +- .../Trino/test_multihop_joined_plan__ep_0.xml | 22 +- ...test_small_combined_metrics_plan__ep_0.xml | 2 +- .../Trino/test_combine_output_node__plan0.sql | 228 +++++++++ ...t_combine_output_node__plan0_optimized.sql | 46 ++ .../test_compute_metrics_node__plan0.sql | 112 ++--- ..._compute_metrics_node__plan0_optimized.sql | 8 +- ...o_from_multiple_semantic_models__plan0.sql | 324 ++++++------ ...tiple_semantic_models__plan0_optimized.sql | 20 +- ...atio_from_single_semantic_model__plan0.sql | 112 ++--- ...single_semantic_model__plan0_optimized.sql | 8 +- ...ompute_metrics_node_simple_expr__plan0.sql | 112 ++--- ...rics_node_simple_expr__plan0_optimized.sql | 8 +- ...on_with_joined_where_constraint__plan0.sql | 229 +++++++++ ...ined_where_constraint__plan0_optimized.sql | 19 + .../test_dimensions_requiring_join__plan0.sql | 164 +++--- ...nsions_requiring_join__plan0_optimized.sql | 14 +- .../Trino/test_multi_join_node__plan0.sql | 224 ++++----- .../test_multi_join_node__plan0_optimized.sql | 4 +- .../Trino/test_single_join_node__plan0.sql | 112 ++--- ...test_single_join_node__plan0_optimized.sql | 4 +- ...set_metric_with_time_constraint__plan0.sql | 442 ++++++++++++++++ ..._with_time_constraint__plan0_optimized.sql | 42 ++ .../Trino/test_derived_metric__plan0.sql | 2 +- .../test_derived_metric__plan0_optimized.sql | 2 +- ...nth_dimension_and_offset_window__plan0.sql | 32 +- ...ion_and_offset_window__plan0_optimized.sql | 6 +- ...ved_metric_with_offset_to_grain__plan0.sql | 2 +- ..._with_offset_to_grain__plan0_optimized.sql | 2 +- ...offset_to_grain_and_granularity__plan0.sql | 2 +- ...grain_and_granularity__plan0_optimized.sql | 2 +- ...rived_metric_with_offset_window__plan0.sql | 2 +- ...ic_with_offset_window__plan0_optimized.sql | 2 +- ...h_offset_window_and_granularity__plan0.sql | 2 +- ...indow_and_granularity__plan0_optimized.sql | 2 +- ...fset_window_and_offset_to_grain__plan0.sql | 2 +- ...w_and_offset_to_grain__plan0_optimized.sql | 2 +- ...offset_to_grain_and_granularity__plan0.sql | 2 +- ...grain_and_granularity__plan0_optimized.sql | 2 +- ...h_offset_window_and_time_filter__plan0.sql | 2 +- ...indow_and_time_filter__plan0_optimized.sql | 2 +- .../test_nested_derived_metric__plan0.sql | 4 +- ...nested_derived_metric__plan0_optimized.sql | 4 +- ...d_where_constraint_not_selected__plan0.sql | 361 +++++++++++++ ...nstraint_not_selected__plan0_optimized.sql | 56 +++ ...h_offset_multiple_input_metrics__plan0.sql | 473 ++++++++++++++++++ ...ultiple_input_metrics__plan0_optimized.sql | 64 +++ .../Trino/test_nested_offsets__plan0.sql | 340 +++++++++++++ .../test_nested_offsets__plan0_optimized.sql | 42 ++ ...ed_offsets_with_time_constraint__plan0.sql | 341 +++++++++++++ ..._with_time_constraint__plan0_optimized.sql | 48 ++ ...d_offsets_with_where_constraint__plan0.sql | 347 +++++++++++++ ...with_where_constraint__plan0_optimized.sql | 49 ++ ...set_metric_with_time_constraint__plan0.sql | 321 ++++++++++++ ..._with_time_constraint__plan0_optimized.sql | 33 ++ ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + .../test_dimensions_requiring_join__plan0.sql | 169 +++++++ ...nsions_requiring_join__plan0_optimized.sql | 14 + ...fill_nulls_for_one_input_metric__plan0.sql | 2 +- ..._for_one_input_metric__plan0_optimized.sql | 2 +- ...st_offset_window_with_date_part__plan0.sql | 2 +- ...window_with_date_part__plan0_optimized.sql | 2 +- ...uery_with_metric_time_dimension__plan0.sql | 2 +- ...metric_time_dimension__plan0_optimized.sql | 2 +- .../test_common_semantic_model__plan0.sql | 2 +- ...common_semantic_model__plan0_optimized.sql | 2 +- .../Trino/test_distinct_values__plan0.sql | 112 ++--- .../test_distinct_values__plan0_optimized.sql | 2 +- ...th_where_constraint_on_join_dim__plan0.sql | 134 ++--- ...onstraint_on_join_dim__plan0_optimized.sql | 20 +- .../test_join_to_scd_dimension__plan0.sql | 270 +++++----- ...join_to_scd_dimension__plan0_optimized.sql | 14 +- ...al_dimension_using_local_entity__plan0.sql | 112 ++--- ...on_using_local_entity__plan0_optimized.sql | 2 +- .../Trino/test_measure_constraint__plan0.sql | 226 ++++----- ...st_measure_constraint__plan0_optimized.sql | 14 +- ..._constraint_with_reused_measure__plan0.sql | 2 +- ...t_with_reused_measure__plan0_optimized.sql | 2 +- ..._multiple_sources_no_dimensions__plan0.sql | 114 ++--- ...sources_no_dimensions__plan0_optimized.sql | 4 +- ...multi_hop_through_scd_dimension__plan0.sql | 322 ++++++------ ...through_scd_dimension__plan0_optimized.sql | 16 +- ...test_multi_hop_to_scd_dimension__plan0.sql | 266 +++++----- ..._hop_to_scd_dimension__plan0_optimized.sql | 16 +- .../Trino/test_multihop_node__plan0.sql | 238 ++++----- .../test_multihop_node__plan0_optimized.sql | 22 +- ..._multiple_metrics_no_dimensions__plan0.sql | 114 ++--- ...metrics_no_dimensions__plan0_optimized.sql | 4 +- .../Trino/test_partitioned_join__plan0.sql | 240 ++++----- ...test_partitioned_join__plan0_optimized.sql | 12 +- 119 files changed, 8239 insertions(+), 2087 deletions(-) create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql create mode 100644 metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/integration/test_cases/itest_constraints.yaml b/metricflow/test/integration/test_cases/itest_constraints.yaml index e641a32211..7022d736ab 100644 --- a/metricflow/test/integration/test_cases/itest_constraints.yaml +++ b/metricflow/test/integration/test_cases/itest_constraints.yaml @@ -142,11 +142,11 @@ integration_test: model: SIMPLE_MODEL metrics: ["bookings"] group_bys: ["metric_time"] - where_filter: "{{ render_time_dimension_template('metric_time') }} = '2020-01-01'" + where_filter: "{{ render_time_dimension_template('metric_time') }} = {{ cast_to_ts('2020-01-01') }}" check_query: | SELECT SUM(1) AS bookings , ds AS metric_time__day FROM {{ source_schema }}.fct_bookings - WHERE ds = '2020-01-01' + WHERE ds = {{ cast_to_ts('2020-01-01') }} GROUP BY ds diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index 67e33cf2ee..26ae81116f 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -1679,7 +1679,7 @@ integration_test: SELECT ds AS metric_time__day FROM {{ source_schema }}.mf_time_spine subq_6 - WHERE ds BETWEEN '2019-12-19' AND '2020-01-02' + WHERE {{ render_between_time_constraint("ds", "2019-12-19", "2020-01-02") }} ) subq_5 INNER JOIN ( SELECT diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql new file mode 100644 index 0000000000..4c0412c4e4 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql @@ -0,0 +1,346 @@ +-- Compute Metrics via Expressions +SELECT + subq_14.buys AS visit_buy_conversions +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_3.visits) AS visits + , COALESCE(MAX(subq_13.buys), 0) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.visits) AS visits + FROM ( + -- Pass Only Elements: + -- ['visits'] + SELECT + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_0 + ) subq_1 + ) subq_2 + ) subq_3 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_12.buys) AS buys + FROM ( + -- Pass Only Elements: + -- ['buys'] + SELECT + subq_11.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 + 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 + FROM ( + -- Pass Only Elements: + -- ['visits', 'ds__day', 'user'] + SELECT + subq_5.ds__day + , subq_5.user + , subq_5.visits + FROM ( + -- Metric Time Dimension 'ds' + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_4 + ) 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 + , 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_10002.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy + , buys_source_src_10002.user_id AS user + , buys_source_src_10002.session_id + , buys_source_src_10002.user_id AS buy__user + , buys_source_src_10002.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_7 + ) subq_8 + ) subq_9 + ON + ( + subq_6.user = subq_9.user + ) AND ( + ( + subq_6.ds__day <= subq_9.ds__day + ) AND ( + subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day) + ) + ) + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 +) subq_14 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..0f90cf24a3 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + COALESCE(MAX(subq_28.buys), 0) AS visit_buy_conversions +FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits'] + -- Aggregate Measures + SELECT + SUM(1) AS visits + FROM ***************************.fct_visits visits_source_src_10011 +) subq_18 +CROSS JOIN ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: + -- ['buys'] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits + , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day + , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.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 + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'ds__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_21 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_24 + ON + ( + subq_21.user = subq_24.user + ) AND ( + ( + subq_21.ds__day <= subq_24.ds__day + ) AND ( + subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day) + ) + ) + ) subq_25 +) subq_28 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql new file mode 100644 index 0000000000..b4aba824fb --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql @@ -0,0 +1,355 @@ +-- 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 +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 + FROM ( + -- Aggregate Measures + SELECT + subq_2.visit__referrer_id + , SUM(subq_2.visits) AS visits + FROM ( + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id'] + SELECT + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.visit__referrer_id + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_12.visit__referrer_id + , SUM(subq_12.buys) AS buys + FROM ( + -- Pass Only Elements: + -- ['buys', 'visit__referrer_id'] + SELECT + subq_11.visit__referrer_id + , subq_11.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 + 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 + FROM ( + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'ds__day', 'user'] + SELECT + subq_5.ds__day + , subq_5.user + , subq_5.visit__referrer_id + , subq_5.visits + FROM ( + -- Metric Time Dimension 'ds' + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_4 + ) 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 + , 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_10002.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy + , buys_source_src_10002.user_id AS user + , buys_source_src_10002.session_id + , buys_source_src_10002.user_id AS buy__user + , buys_source_src_10002.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_10002 + ) 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 + GROUP BY + subq_12.visit__referrer_id + ) subq_13 + ON + subq_3.visit__referrer_id = subq_13.visit__referrer_id + GROUP BY + COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) +) subq_14 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql new file mode 100644 index 0000000000..9f0493d406 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql @@ -0,0 +1,83 @@ +-- Compute Metrics via Expressions +SELECT + visit__referrer_id + , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate +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 + FROM ( + -- Aggregate Measures + SELECT + visit__referrer_id + , SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id'] + SELECT + referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_17 + GROUP BY + visit__referrer_id + ) subq_18 + FULL OUTER JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: + -- ['buys', 'visit__referrer_id'] + -- Aggregate Measures + SELECT + visit__referrer_id + , SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id + , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day + , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.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 + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'ds__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_21 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_24 + ON + ( + subq_21.user = subq_24.user + ) AND ( + (subq_21.ds__day <= subq_24.ds__day) + ) + ) subq_25 + GROUP BY + visit__referrer_id + ) subq_28 + ON + subq_18.visit__referrer_id = subq_28.visit__referrer_id + GROUP BY + COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) +) subq_29 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql new file mode 100644 index 0000000000..60b4af433e --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql @@ -0,0 +1,389 @@ +-- 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 +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 + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , subq_2.visit__referrer_id + , SUM(subq_2.visits) AS visits + FROM ( + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'metric_time__day'] + SELECT + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.visit__referrer_id + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , subq_12.visit__referrer_id + , SUM(subq_12.buys) AS buys + FROM ( + -- 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 ( + -- 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 + 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 + FROM ( + -- Pass Only Elements: + -- ['visits', + -- 'visit__referrer_id', + -- 'ds__day', + -- 'metric_time__day', + -- 'user', + -- 'session'] + SELECT + subq_5.ds__day + , subq_5.metric_time__day + , subq_5.user + , subq_5.session + , subq_5.visit__referrer_id + , subq_5.visits + FROM ( + -- Metric Time Dimension 'ds' + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_4 + ) 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 + , 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_10002.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy + , buys_source_src_10002.user_id AS user + , buys_source_src_10002.session_id + , buys_source_src_10002.user_id AS buy__user + , buys_source_src_10002.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_7 + ) subq_8 + ) subq_9 + ON + ( + subq_6.user = subq_9.user + ) AND ( + subq_6.session = subq_9.session_id + ) AND ( + ( + subq_6.ds__day <= subq_9.ds__day + ) AND ( + subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day) + ) + ) + ) subq_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + , subq_12.visit__referrer_id + ) subq_13 + ON + ( + subq_3.visit__referrer_id = subq_13.visit__referrer_id + ) AND ( + subq_3.metric_time__day = subq_13.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 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql new file mode 100644 index 0000000000..dd31bc8ef0 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql @@ -0,0 +1,111 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , visit__referrer_id + , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_by_session +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 + FROM ( + -- Aggregate Measures + SELECT + metric_time__day + , visit__referrer_id + , SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_17 + GROUP BY + metric_time__day + , visit__referrer_id + ) subq_18 + FULL OUTER JOIN ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: + -- ['buys', 'visit__referrer_id', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , visit__referrer_id + , SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS session + , subq_24.mf_internal_uuid AS mf_internal_uuid + , subq_24.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', + -- 'visit__referrer_id', + -- 'ds__day', + -- 'metric_time__day', + -- 'user', + -- 'session'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , session_id AS session + , referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_21 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , session_id + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_24 + ON + ( + subq_21.user = subq_24.user + ) AND ( + subq_21.session = subq_24.session_id + ) AND ( + ( + subq_21.ds__day <= subq_24.ds__day + ) AND ( + subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day) + ) + ) + ) subq_25 + GROUP BY + metric_time__day + , visit__referrer_id + ) subq_28 + ON + ( + subq_18.visit__referrer_id = subq_28.visit__referrer_id + ) AND ( + subq_18.metric_time__day = subq_28.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 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql new file mode 100644 index 0000000000..7ca65cd123 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql @@ -0,0 +1,346 @@ +-- 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 +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_3.visits) AS visits + , MAX(subq_13.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_2.visits) AS visits + FROM ( + -- Pass Only Elements: + -- ['visits'] + SELECT + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_0 + ) subq_1 + ) subq_2 + ) subq_3 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_12.buys) AS buys + FROM ( + -- Pass Only Elements: + -- ['buys'] + SELECT + subq_11.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 + 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 + FROM ( + -- Pass Only Elements: + -- ['visits', 'ds__day', 'user'] + SELECT + subq_5.ds__day + , subq_5.user + , subq_5.visits + FROM ( + -- Metric Time Dimension 'ds' + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_4 + ) 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 + , 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_10002.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy + , buys_source_src_10002.user_id AS user + , buys_source_src_10002.session_id + , buys_source_src_10002.user_id AS buy__user + , buys_source_src_10002.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_7 + ) subq_8 + ) subq_9 + ON + ( + subq_6.user = subq_9.user + ) AND ( + ( + subq_6.ds__day <= subq_9.ds__day + ) AND ( + subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day) + ) + ) + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 +) subq_14 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..69b10a78a8 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql @@ -0,0 +1,63 @@ +-- 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 +FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits'] + -- Aggregate Measures + SELECT + SUM(1) AS visits + FROM ***************************.fct_visits visits_source_src_10011 +) subq_18 +CROSS JOIN ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: + -- ['buys'] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits + , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day + , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.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 + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'ds__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_21 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_24 + ON + ( + subq_21.user = subq_24.user + ) AND ( + ( + subq_21.ds__day <= subq_24.ds__day + ) AND ( + subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day) + ) + ) + ) subq_25 +) subq_28 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql new file mode 100644 index 0000000000..2ecf6c63a9 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql @@ -0,0 +1,379 @@ +-- 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 +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 + FROM ( + -- Aggregate Measures + SELECT + subq_2.metric_time__day + , subq_2.visit__referrer_id + , SUM(subq_2.visits) AS visits + FROM ( + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'metric_time__day'] + SELECT + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_0 + ) subq_1 + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.visit__referrer_id + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , subq_12.visit__referrer_id + , SUM(subq_12.buys) AS buys + FROM ( + -- 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 ( + -- 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 + 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 + FROM ( + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_5.ds__day + , subq_5.metric_time__day + , subq_5.user + , subq_5.visit__referrer_id + , subq_5.visits + FROM ( + -- Metric Time Dimension 'ds' + 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_10011.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy + , visits_source_src_10011.referrer_id + , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy + , visits_source_src_10011.referrer_id AS visit__referrer_id + , visits_source_src_10011.user_id AS user + , visits_source_src_10011.session_id AS session + , visits_source_src_10011.user_id AS visit__user + , visits_source_src_10011.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_4 + ) 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 + , 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_10002.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy + , buys_source_src_10002.user_id AS user + , buys_source_src_10002.session_id + , buys_source_src_10002.user_id AS buy__user + , buys_source_src_10002.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_7 + ) subq_8 + ) subq_9 + ON + ( + subq_6.user = subq_9.user + ) AND ( + ( + subq_6.ds__day <= subq_9.ds__day + ) AND ( + subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day) + ) + ) + ) subq_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + , subq_12.visit__referrer_id + ) subq_13 + ON + ( + subq_3.visit__referrer_id = subq_13.visit__referrer_id + ) AND ( + subq_3.metric_time__day = subq_13.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 diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql new file mode 100644 index 0000000000..358169cce7 --- /dev/null +++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql @@ -0,0 +1,101 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , visit__referrer_id + , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days +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 + FROM ( + -- Aggregate Measures + SELECT + metric_time__day + , visit__referrer_id + , SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_17 + GROUP BY + metric_time__day + , visit__referrer_id + ) subq_18 + FULL OUTER JOIN ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: + -- ['buys', 'visit__referrer_id', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , visit__referrer_id + , SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id + , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day + , first_value(subq_21.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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day + , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.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 + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , referrer_id AS visit__referrer_id + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_10011 + ) subq_21 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_10002 + ) subq_24 + ON + ( + subq_21.user = subq_24.user + ) AND ( + ( + subq_21.ds__day <= subq_24.ds__day + ) AND ( + subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day) + ) + ) + ) subq_25 + GROUP BY + metric_time__day + , visit__referrer_id + ) subq_28 + ON + ( + subq_18.visit__referrer_id = subq_28.visit__referrer_id + ) AND ( + subq_18.metric_time__day = subq_28.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 diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql index 1807b48040..b615260818 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql @@ -1,28 +1,28 @@ -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user -FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user +FROM ***************************.fct_revenue revenue_src_10007 diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql index 9836f4381d..26ee6990b0 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql @@ -1,53 +1,53 @@ -- Read Elements From Semantic Model 'id_verifications' SELECT 1 AS identity_verifications - , DATE_TRUNC('day', id_verifications_src_10003.ds) AS ds__day - , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week - , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds) AS ds__year - , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy - , id_verifications_src_10003.verification_type - , DATE_TRUNC('day', id_verifications_src_10003.ds) AS verification__ds__day - , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week - , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds) AS verification__ds__year - , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy - , id_verifications_src_10003.verification_type AS verification__verification_type - , id_verifications_src_10003.verification_id AS verification - , id_verifications_src_10003.user_id AS user - , id_verifications_src_10003.user_id AS verification__user -FROM ***************************.fct_id_verifications id_verifications_src_10003 + , DATE_TRUNC('day', id_verifications_src_10004.ds) AS ds__day + , DATE_TRUNC('week', id_verifications_src_10004.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_10004.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_10004.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds) AS ds__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds) AS ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_10004.verification_type + , DATE_TRUNC('day', id_verifications_src_10004.ds) AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_10004.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_10004.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_10004.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds) AS verification__ds__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds) AS verification__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds) AS verification__ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_10004.verification_type AS verification__verification_type + , id_verifications_src_10004.verification_id AS verification + , id_verifications_src_10004.user_id AS user + , id_verifications_src_10004.user_id AS verification__user +FROM ***************************.fct_id_verifications id_verifications_src_10004 diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql index 35b84cedba..d14cc5b651 100644 --- a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql +++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql @@ -1,28 +1,28 @@ -- Read Elements From Semantic Model 'users_latest' SELECT - DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy - , users_latest_src_10008.home_state_latest - , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy - , users_latest_src_10008.home_state_latest AS user__home_state_latest - , users_latest_src_10008.user_id AS user -FROM ***************************.dim_users_latest users_latest_src_10008 + DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy + , users_latest_src_10009.home_state_latest + , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy + , users_latest_src_10009.home_state_latest AS user__home_state_latest + , users_latest_src_10009.user_id AS user +FROM ***************************.dim_users_latest users_latest_src_10009 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql index a19fbc0ed7..2f9b5fe681 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql @@ -55,32 +55,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql index 6596468bca..efe2244b0f 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql @@ -7,6 +7,6 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS trailing_2_months_revenue -FROM ***************************.fct_revenue revenue_src_10006 +FROM ***************************.fct_revenue revenue_src_10007 GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql index 689c32ba68..ca08f80e45 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql @@ -55,32 +55,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql index 06853be07e..a44bb5a72b 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql @@ -7,6 +7,6 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS revenue_mtd -FROM ***************************.fct_revenue revenue_src_10006 +FROM ***************************.fct_revenue revenue_src_10007 GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql index 5d6708585a..afce151a3d 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql @@ -52,32 +52,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql index ba2c45a4ca..30e9e6946d 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql @@ -6,4 +6,4 @@ -- Compute Metrics via Expressions SELECT SUM(revenue) AS trailing_2_months_revenue -FROM ***************************.fct_revenue revenue_src_10006 +FROM ***************************.fct_revenue revenue_src_10007 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql index 291d6de321..5062fa6a66 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql @@ -55,32 +55,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql index 220fb6083c..ccf3a0f545 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql @@ -7,6 +7,6 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS revenue_all_time -FROM ***************************.fct_revenue revenue_src_10006 +FROM ***************************.fct_revenue revenue_src_10007 GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql index 9c6155e377..f5cde6f1a4 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -94,32 +94,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 WHERE subq_1.metric_time__day BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql index c8d6cd46c9..2553df7dec 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -8,7 +8,7 @@ SELECT DATE_TRUNC('month', created_at) AS ds__month , SUM(revenue) AS revenue_all_time -FROM ***************************.fct_revenue revenue_src_10006 +FROM ***************************.fct_revenue revenue_src_10007 WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01' GROUP BY DATE_TRUNC('month', created_at) diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql index aab524ac8b..db1370b7a0 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql @@ -65,7 +65,7 @@ FROM ( WHERE subq_4.ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_3 INNER JOIN ( - -- Constrain Time Range to [2019-12-01T00:00:00, 2020-01-01T00:00:00] + -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00] SELECT subq_1.ds__day , subq_1.ds__week @@ -145,35 +145,35 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'revenue' SELECT - revenue_src_10006.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_10006.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_10006.created_at) AS company__ds__day - , DATE_TRUNC('week', revenue_src_10006.created_at) AS company__ds__week - , DATE_TRUNC('month', revenue_src_10006.created_at) AS company__ds__month - , DATE_TRUNC('quarter', revenue_src_10006.created_at) AS company__ds__quarter - , DATE_TRUNC('year', revenue_src_10006.created_at) AS company__ds__year - , EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year - , EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter - , EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month - , EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow - , EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy - , revenue_src_10006.user_id AS user - , revenue_src_10006.user_id AS company__user - FROM ***************************.fct_revenue revenue_src_10006 + revenue_src_10007.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day + , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week + , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month + , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter + , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year + , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year + , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter + , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month + , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow + , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy + , revenue_src_10007.user_id AS user + , revenue_src_10007.user_id AS company__user + FROM ***************************.fct_revenue revenue_src_10007 ) subq_0 ) subq_1 - WHERE subq_1.metric_time__day BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' + WHERE subq_1.metric_time__day BETWEEN timestamp '2019-11-01' AND timestamp '2020-01-01' ) subq_2 ON ( diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql index df4cc42b14..07569fc878 100644 --- a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -17,13 +17,13 @@ FROM ( INNER JOIN ( -- Read Elements From Semantic Model 'revenue' -- Metric Time Dimension 'ds' - -- Constrain Time Range to [2019-12-01T00:00:00, 2020-01-01T00:00:00] + -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00] SELECT DATE_TRUNC('day', created_at) AS metric_time__day , DATE_TRUNC('month', created_at) AS metric_time__month , revenue AS txn_revenue - FROM ***************************.fct_revenue revenue_src_10006 - WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2019-12-01' AND timestamp '2020-01-01' + FROM ***************************.fct_revenue revenue_src_10007 + WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2019-11-01' AND timestamp '2020-01-01' ) subq_11 ON ( diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml index 1768aeaecd..bdab0b0d91 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml @@ -3,7 +3,7 @@ - + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml index 99c2c23a43..e224019fce 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml @@ -10,7 +10,7 @@ - + @@ -24,11 +24,11 @@ - + - + - + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml index ab375ac0d1..c5d17a25a0 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml @@ -10,31 +10,31 @@ - - + + - - - - + + + + - + - + - + - + - + diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml index 53612723d0..57ca2f3d3c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml @@ -3,7 +3,7 @@ - + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql new file mode 100644 index 0000000000..e0fa9b4f05 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql @@ -0,0 +1,228 @@ +-- 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 +FROM ( + -- Aggregate Measures + SELECT + subq_1.is_instant + , SUM(subq_1.bookings) AS bookings + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + GROUP BY + subq_1.is_instant +) subq_2 +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 + FROM ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_3 + ) subq_4 + GROUP BY + subq_4.is_instant +) subq_5 +ON + subq_2.is_instant = subq_5.is_instant +GROUP BY + COALESCE(subq_2.is_instant, subq_5.is_instant) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql new file mode 100644 index 0000000000..62340aabcb --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql @@ -0,0 +1,46 @@ +-- 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 +FROM ( + -- Aggregate Measures + SELECT + is_instant + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Pass Only Elements: + -- ['bookings', 'is_instant'] + SELECT + is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_7 + GROUP BY + is_instant +) subq_8 +FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + is_instant + , SUM(instant_bookings) AS instant_bookings + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model '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 + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_10 + GROUP BY + is_instant +) subq_11 +ON + subq_8.is_instant = subq_11.is_instant +GROUP BY + COALESCE(subq_8.is_instant, subq_11.is_instant) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql index cf20471005..8cd1791e75 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql @@ -125,62 +125,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_2 ) subq_3 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql index 7a53d1c84e..9e5210f489 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql @@ -3,7 +3,7 @@ -- Compute Metrics via Expressions SELECT subq_7.listing AS listing - , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10005.country AS listing__country_latest , SUM(subq_7.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' @@ -15,9 +15,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_7 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_7.listing = listings_latest_src_10004.listing_id + subq_7.listing = listings_latest_src_10005.listing_id GROUP BY subq_7.listing - , listings_latest_src_10004.country + , listings_latest_src_10005.country diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index a33332f579..a2b37da09b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql @@ -4,7 +4,7 @@ SELECT , subq_20.listing__country_latest , CAST(subq_20.bookings AS DOUBLE) / CAST(NULLIF(subq_20.views, 0) AS DOUBLE) AS bookings_per_view FROM ( - -- Combine Metrics + -- 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 @@ -319,62 +319,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_3 ) subq_4 ) subq_5 @@ -487,55 +487,55 @@ FROM ( -- Read Elements From Semantic Model 'views_source' SELECT 1 AS views - , DATE_TRUNC('day', views_source_src_10009.ds) AS ds__day - , DATE_TRUNC('week', views_source_src_10009.ds) AS ds__week - , DATE_TRUNC('month', views_source_src_10009.ds) AS ds__month - , DATE_TRUNC('quarter', views_source_src_10009.ds) AS ds__quarter - , DATE_TRUNC('year', views_source_src_10009.ds) AS ds__year - , EXTRACT(year FROM views_source_src_10009.ds) AS ds__extract_year - , EXTRACT(quarter FROM views_source_src_10009.ds) AS ds__extract_quarter - , EXTRACT(month FROM views_source_src_10009.ds) AS ds__extract_month - , EXTRACT(day FROM views_source_src_10009.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds) AS ds__extract_dow - , EXTRACT(doy FROM views_source_src_10009.ds) AS ds__extract_doy - , DATE_TRUNC('day', views_source_src_10009.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_10009.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', views_source_src_10009.ds) AS view__ds__day - , DATE_TRUNC('week', views_source_src_10009.ds) AS view__ds__week - , DATE_TRUNC('month', views_source_src_10009.ds) AS view__ds__month - , DATE_TRUNC('quarter', views_source_src_10009.ds) AS view__ds__quarter - , DATE_TRUNC('year', views_source_src_10009.ds) AS view__ds__year - , EXTRACT(year FROM views_source_src_10009.ds) AS view__ds__extract_year - , EXTRACT(quarter FROM views_source_src_10009.ds) AS view__ds__extract_quarter - , EXTRACT(month FROM views_source_src_10009.ds) AS view__ds__extract_month - , EXTRACT(day FROM views_source_src_10009.ds) AS view__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds) AS view__ds__extract_dow - , EXTRACT(doy FROM views_source_src_10009.ds) AS view__ds__extract_doy - , DATE_TRUNC('day', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__day - , DATE_TRUNC('week', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__week - , DATE_TRUNC('month', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_10009.ds_partitioned) AS view__ds_partitioned__year - , EXTRACT(year FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_10009.ds_partitioned) AS view__ds_partitioned__extract_doy - , views_source_src_10009.listing_id AS listing - , views_source_src_10009.user_id AS user - , views_source_src_10009.listing_id AS view__listing - , views_source_src_10009.user_id AS view__user - FROM ***************************.fct_views views_source_src_10009 + , DATE_TRUNC('day', views_source_src_10010.ds) AS ds__day + , DATE_TRUNC('week', views_source_src_10010.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_10010.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_10010.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_10010.ds) AS ds__year + , EXTRACT(year FROM views_source_src_10010.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_10010.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_10010.ds) AS ds__extract_month + , EXTRACT(day FROM views_source_src_10010.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_10010.ds) AS ds__extract_doy + , DATE_TRUNC('day', views_source_src_10010.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_10010.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_10010.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_10010.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_10010.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', views_source_src_10010.ds) AS view__ds__day + , DATE_TRUNC('week', views_source_src_10010.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_10010.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_10010.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_10010.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_10010.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_10010.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_10010.ds) AS view__ds__extract_month + , EXTRACT(day FROM views_source_src_10010.ds) AS view__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_10010.ds) AS view__ds__extract_doy + , DATE_TRUNC('day', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_10010.listing_id AS listing + , views_source_src_10010.user_id AS user + , views_source_src_10010.listing_id AS view__listing + , views_source_src_10010.user_id AS view__user + FROM ***************************.fct_views views_source_src_10010 ) subq_10 ) subq_11 ) subq_12 @@ -619,62 +619,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_13 ) subq_14 ) subq_15 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index b53b1f06f4..ee6adb1fd6 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql @@ -4,7 +4,7 @@ SELECT , listing__country_latest , CAST(bookings AS DOUBLE) / CAST(NULLIF(views, 0) AS DOUBLE) AS bookings_per_view FROM ( - -- Combine Metrics + -- 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 @@ -18,7 +18,7 @@ FROM ( -- Compute Metrics via Expressions SELECT subq_23.ds__day AS ds__day - , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10005.country AS listing__country_latest , SUM(subq_23.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' @@ -32,12 +32,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_23 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_23.listing = listings_latest_src_10004.listing_id + subq_23.listing = listings_latest_src_10005.listing_id GROUP BY subq_23.ds__day - , listings_latest_src_10004.country + , listings_latest_src_10005.country ) subq_30 FULL OUTER JOIN ( -- Join Standard Outputs @@ -47,7 +47,7 @@ FROM ( -- Compute Metrics via Expressions SELECT subq_33.ds__day AS ds__day - , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10005.country AS listing__country_latest , SUM(subq_33.views) AS views FROM ( -- Read Elements From Semantic Model 'views_source' @@ -58,15 +58,15 @@ FROM ( DATE_TRUNC('day', ds) AS ds__day , listing_id AS listing , 1 AS views - FROM ***************************.fct_views views_source_src_10009 + FROM ***************************.fct_views views_source_src_10010 ) subq_33 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_33.listing = listings_latest_src_10004.listing_id + subq_33.listing = listings_latest_src_10005.listing_id GROUP BY subq_33.ds__day - , listings_latest_src_10004.country + , listings_latest_src_10005.country ) subq_40 ON ( diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql index 7d16206c12..d8fa906713 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql @@ -128,62 +128,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_2 ) subq_3 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql index f22bdaf7cb..0bfa1bff7f 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Aggregate Measures SELECT subq_7.listing AS listing - , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10005.country AS listing__country_latest , SUM(subq_7.bookings) AS bookings , COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( @@ -22,10 +22,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_7 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_7.listing = listings_latest_src_10004.listing_id + subq_7.listing = listings_latest_src_10005.listing_id GROUP BY subq_7.listing - , listings_latest_src_10004.country + , listings_latest_src_10005.country ) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql index 2ebae4d754..22428879cc 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql @@ -125,62 +125,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_2 ) subq_3 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql index caa4c0c6fe..5a844f2632 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql @@ -8,14 +8,14 @@ FROM ( -- Aggregate Measures SELECT bookings_source_src_10001.listing_id AS listing - , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10005.country AS listing__country_latest , SUM(bookings_source_src_10001.booking_value) AS booking_value FROM ***************************.fct_bookings bookings_source_src_10001 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id + bookings_source_src_10001.listing_id = listings_latest_src_10005.listing_id GROUP BY bookings_source_src_10001.listing_id - , listings_latest_src_10004.country + , listings_latest_src_10005.country ) subq_11 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql new file mode 100644 index 0000000000..51a97deab5 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql @@ -0,0 +1,229 @@ +-- Pass Only Elements: +-- ['user__home_state_latest'] +SELECT + subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + 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 + FROM ( + -- Join Standard Outputs + 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_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 + ) 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_10009.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy + , users_latest_src_10009.home_state_latest + , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy + , users_latest_src_10009.home_state_latest AS user__home_state_latest + , users_latest_src_10009.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10009 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE listing__country_latest = 'us' +) subq_4 +GROUP BY + subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..bbb933bac0 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -0,0 +1,19 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest'] +SELECT + user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10005.country AS listing__country_latest + , users_latest_src_10009.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10005 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10009 + ON + listings_latest_src_10005.user_id = users_latest_src_10009.user_id +) subq_8 +WHERE listing__country_latest = 'us' +GROUP BY + user__home_state_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql index acae28a7e4..77f81a9548 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql @@ -67,62 +67,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_0 FULL OUTER JOIN ( -- Pass Only Elements: @@ -133,32 +133,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT - DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy - , users_latest_src_10008.home_state_latest - , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy - , users_latest_src_10008.home_state_latest AS user__home_state_latest - , users_latest_src_10008.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_10008 + DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy + , users_latest_src_10009.home_state_latest + , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy + , users_latest_src_10009.home_state_latest AS user__home_state_latest + , users_latest_src_10009.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10009 ) subq_1 ) subq_2 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql index 4bf3539984..7f093b6070 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql @@ -2,13 +2,13 @@ -- Pass Only Elements: -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - listings_latest_src_10004.is_lux AS listing__is_lux_latest - , users_latest_src_10008.home_state_latest AS user__home_state_latest -FROM ***************************.dim_listings_latest listings_latest_src_10004 + listings_latest_src_10005.is_lux AS listing__is_lux_latest + , users_latest_src_10009.home_state_latest AS user__home_state_latest +FROM ***************************.dim_listings_latest listings_latest_src_10005 FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_10008 + ***************************.dim_users_latest users_latest_src_10009 ON - listings_latest_src_10004.user_id = users_latest_src_10008.user_id + listings_latest_src_10005.user_id = users_latest_src_10009.user_id GROUP BY - listings_latest_src_10004.is_lux - , users_latest_src_10008.home_state_latest + listings_latest_src_10005.is_lux + , users_latest_src_10009.home_state_latest diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql index 2ad002ed1a..26d887d309 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql @@ -114,62 +114,62 @@ LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_2 ) subq_3 ON @@ -184,62 +184,62 @@ LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_4 ) subq_5 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql index 8180d208b3..ddfc1d9706 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql @@ -20,7 +20,7 @@ LEFT OUTER JOIN ( SELECT listing_id AS listing , country AS country_latest - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_9 ON subq_7.listing = subq_9.listing @@ -31,7 +31,7 @@ LEFT OUTER JOIN ( SELECT listing_id AS listing , country AS country_latest - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_11 ON subq_7.listing = subq_11.listing diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql index 73da0ff4d9..9d596e7b4b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql @@ -112,62 +112,62 @@ LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_2 ) subq_3 ON diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql index 480a2c9f56..9202940446 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql @@ -12,6 +12,6 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_5 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_5.listing = listings_latest_src_10004.listing_id + subq_5.listing = listings_latest_src_10005.listing_id diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..f60fe55ef8 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -0,0 +1,442 @@ +-- Compute Metrics via Expressions +SELECT + subq_11.metric_time__day + , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , subq_10.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 + FROM ( + -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] + SELECT + subq_8.metric_time__day + , subq_8.bookers + FROM ( + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + SELECT + subq_7.metric_time__day + , subq_7.bookers + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_5.metric_time__day AS metric_time__day + , 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 + FROM ( + -- Date Spine + SELECT + subq_6.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_6 + WHERE subq_6.ds BETWEEN timestamp '2019-12-19' AND timestamp '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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day) + ) + ) subq_4 + ON + DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day + ) subq_7 + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + ) subq_9 + GROUP BY + subq_9.metric_time__day + ) subq_10 +) subq_11 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..2d70867cb1 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookers', 'metric_time__day'] + -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] + -- 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 + FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_18 + WHERE ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + ) subq_17 + INNER JOIN ( + -- Join Self Over Time Range + SELECT + subq_15.ds AS metric_time__day + , bookings_source_src_10001.guest_id AS bookers + FROM ***************************.mf_time_spine subq_15 + INNER JOIN + ***************************.fct_bookings bookings_source_src_10001 + ON + ( + DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_15.ds + ) AND ( + DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_15.ds) + ) + ) subq_16 + ON + DATE_ADD('day', -2, subq_17.metric_time__day) = subq_16.metric_time__day + WHERE subq_17.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + GROUP BY + subq_17.metric_time__day +) subq_23 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql index 49c690395d..564d6e351d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_10.metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql index f7d37d45b3..b3e757c0c6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct FROM ( - -- Combine Metrics + -- Combine Aggregated Outputs SELECT COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) AS metric_time__day , MAX(subq_15.ref_bookings) AS ref_bookings diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 69afbb9475..6823712051 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -72,22 +72,22 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'bookings_monthly_source' SELECT - bookings_monthly_source_src_10024.bookings_monthly - , DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_month - , DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_month - , bookings_monthly_source_src_10024.listing_id AS listing - , bookings_monthly_source_src_10024.listing_id AS booking__listing - FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 + bookings_monthly_source_src_10026.bookings_monthly + , DATE_TRUNC('month', bookings_monthly_source_src_10026.ds) AS monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_10026.ds) AS monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_10026.ds) AS monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_month + , DATE_TRUNC('month', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_month + , bookings_monthly_source_src_10026.listing_id AS listing + , bookings_monthly_source_src_10026.listing_id AS booking__listing + FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026 ) subq_0 ) subq_1 ON diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index dfd07817f3..583a06e6b4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -10,7 +10,7 @@ FROM ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__month AS metric_time__month - , SUM(bookings_monthly_source_src_10024.bookings_monthly) AS bookings_last_month + , SUM(bookings_monthly_source_src_10026.bookings_monthly) AS bookings_last_month FROM ( -- Date Spine SELECT @@ -20,9 +20,9 @@ FROM ( DATE_TRUNC('month', ds) ) subq_10 INNER JOIN - ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 + ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026 ON - DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) + DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10026.ds) GROUP BY subq_10.metric_time__month ) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql index ae1243737c..17e672d736 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_13.metric_time__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 6d1b17b416..3763e526e9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index e32be63ced..bf6bf89e6c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_13.metric_time__week , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 5b18fcfa5f..0ac0bf4ca1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__week , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index 10760992bd..26749f75df 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_13.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql index 7ad5604b52..3affc98215 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 89b794993f..1644094ca9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_13.metric_time__quarter , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index d272b406e6..daa0503cca 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__quarter , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index c678d364d3..b1e0452fac 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_16.metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 74be8a4d15..c708273e6e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 0a7185d41a..4161462b4d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_16.metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 9104a34910..2c0a228856 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index a4af805358..44aeb8a341 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_15.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 9d5acb0380..d1ff5de63a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql index 1d2d351788..58d37cfe4c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_22.metric_time__day , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct FROM ( - -- Combine Metrics + -- 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 @@ -15,7 +15,7 @@ FROM ( subq_10.metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql index 86124d9091..97c8543446 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct FROM ( - -- Combine Metrics + -- Combine Aggregated Outputs SELECT COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day) AS metric_time__day , MAX(subq_34.non_referred) AS non_referred @@ -15,7 +15,7 @@ FROM ( metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred FROM ( - -- Combine Metrics + -- Combine Aggregated Outputs SELECT COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day , MAX(subq_27.ref_bookings) AS ref_bookings diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql new file mode 100644 index 0000000000..d02e51891b --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -0,0 +1,361 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , 2 * bookings_offset_once AS bookings_offset_twice +FROM ( + -- Pass Only Elements: + -- ['metric_time__day', 'bookings_offset_once'] + SELECT + subq_12.metric_time__day + , subq_12.bookings_offset_once + FROM ( + -- Constrain Output with WHERE + SELECT + subq_11.metric_time__day + , subq_11.booking__is_instant + , subq_11.bookings_offset_once + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_8.booking__is_instant AS booking__is_instant + , subq_8.bookings_offset_once AS bookings_offset_once + FROM ( + -- Date 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 + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.booking__is_instant + , subq_6.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_ADD('day', -5, subq_2.metric_time__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 + DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day + ) subq_11 + WHERE booking__is_instant + ) subq_12 +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql new file mode 100644 index 0000000000..e949bb12a5 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -0,0 +1,56 @@ +-- Compute Metrics via Expressions +SELECT + 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 + metric_time__day + , bookings_offset_once + 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 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , booking__is_instant + , 2 * bookings AS bookings_offset_once + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'booking__is_instant', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_15 + ON + DATE_ADD('day', -5, subq_17.ds) = subq_15.metric_time__day + GROUP BY + subq_17.ds + , subq_15.booking__is_instant + ) subq_21 + ) subq_22 + ON + DATE_ADD('day', -2, subq_24.ds) = subq_22.metric_time__day + ) subq_25 + WHERE booking__is_instant +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql new file mode 100644 index 0000000000..5fb0085985 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -0,0 +1,473 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.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 + 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 + FROM ( + -- Date Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_4.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 + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) 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 + 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + ) subq_14 + ON + subq_8.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql new file mode 100644 index 0000000000..d26294499f --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month +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 + 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 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , booking_value * 0.05 AS booking_fees_start_of_month + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_20 + ) subq_21 + ON + DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day + ) subq_24 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , booking_value * 0.05 AS booking_fees + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , SUM(booking_value) AS booking_value + FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_29 + ) subq_30 + ON + subq_24.metric_time__day = subq_30.metric_time__day + GROUP BY + COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) +) subq_31 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql new file mode 100644 index 0000000000..9dd2d000cc --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql @@ -0,0 +1,340 @@ +-- Compute Metrics via Expressions +SELECT + subq_11.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 + FROM ( + -- Date 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 + , 2 * bookings AS bookings_offset_once + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ) subq_7 + ) subq_8 + ON + DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day +) subq_11 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql new file mode 100644 index 0000000000..9b5674304c --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql @@ -0,0 +1,42 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , 2 * bookings_offset_once AS bookings_offset_twice +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 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , 2 * bookings AS bookings_offset_once + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + ON + DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day + GROUP BY + subq_15.ds + ) subq_19 + ) subq_20 + ON + DATE_ADD('day', -2, subq_22.ds) = subq_20.metric_time__day +) subq_23 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..e9543a2a73 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql @@ -0,0 +1,341 @@ +-- Compute Metrics via Expressions +SELECT + subq_11.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 + FROM ( + -- Date Spine + SELECT + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + WHERE subq_10.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' + ) subq_9 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_7.metric_time__day + , 2 * bookings AS bookings_offset_once + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ) subq_7 + ) subq_8 + ON + DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day +) subq_11 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..e00400a25b --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,48 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , 2 * bookings_offset_once AS bookings_offset_twice +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 + FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + WHERE ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' + ) subq_21 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , 2 * bookings AS bookings_offset_once + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_13 + ON + DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day + GROUP BY + subq_15.ds + ) subq_19 + ) subq_20 + ON + DATE_ADD('day', -2, subq_21.metric_time__day) = subq_20.metric_time__day +) subq_23 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql new file mode 100644 index 0000000000..39198ed5f4 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql @@ -0,0 +1,347 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.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 + 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 + FROM ( + -- Date 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 + , 2 * bookings AS bookings_offset_once + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.bookings + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 + ) subq_7 + ) subq_8 + ON + DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day + ) subq_11 + WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' +) subq_12 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..a594f89255 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -0,0 +1,49 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , 2 * bookings_offset_once AS bookings_offset_twice +FROM ( + -- Constrain Output with WHERE + SELECT + metric_time__day + , bookings_offset_once + 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 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + metric_time__day + , 2 * bookings AS bookings_offset_once + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_14 + ON + DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day + GROUP BY + subq_16.ds + ) subq_20 + ) subq_21 + ON + DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day + ) subq_24 + WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' +) subq_25 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql new file mode 100644 index 0000000000..3512e061f0 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql @@ -0,0 +1,321 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.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 + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + 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.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 ( + -- Date Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + WHERE subq_3.ds BETWEEN timestamp '2019-12-19' AND timestamp '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 ( + -- 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_10001.booking_value + , bookings_source_src_10001.booking_value AS max_booking_value + , bookings_source_src_10001.booking_value AS min_booking_value + , bookings_source_src_10001.guest_id AS bookers + , bookings_source_src_10001.booking_value AS average_booking_value + , bookings_source_src_10001.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_10001.booking_value AS median_booking_value + , bookings_source_src_10001.booking_value AS booking_value_p99 + , bookings_source_src_10001.booking_value AS discrete_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_10001.is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy + , bookings_source_src_10001.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10001.listing_id AS listing + , bookings_source_src_10001.guest_id AS guest + , bookings_source_src_10001.host_id AS host + , bookings_source_src_10001.listing_id AS booking__listing + , bookings_source_src_10001.guest_id AS booking__guest + , bookings_source_src_10001.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_0 + ) subq_1 + ON + DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql new file mode 100644 index 0000000000..0473434ea6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , bookings_5_days_ago AS bookings_5_day_lag +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: + -- ['bookings', 'metric_time__day'] + -- 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 + FROM ( + -- Date Spine + SELECT + ds AS metric_time__day + FROM ***************************.mf_time_spine subq_11 + WHERE ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + ) subq_10 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10001 + ) subq_9 + ON + DATE_ADD('day', -5, subq_10.metric_time__day) = subq_9.metric_time__day + GROUP BY + subq_10.metric_time__day +) subq_15 diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..6442c922a7 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + 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 + FROM ( + -- Join Standard Outputs + 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_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 + ) 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_10009.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy + , users_latest_src_10009.home_state_latest + , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy + , users_latest_src_10009.home_state_latest AS user__home_state_latest + , users_latest_src_10009.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10009 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..533b86774d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10005.is_lux AS listing__is_lux_latest + , users_latest_src_10009.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10005 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10009 + ON + listings_latest_src_10005.user_id = users_latest_src_10009.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql new file mode 100644 index 0000000000..77f81a9548 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql @@ -0,0 +1,169 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_3.listing__is_lux_latest + , subq_3.user__home_state_latest +FROM ( + -- Join Standard Outputs + 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_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 + ) 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_10009.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy + , users_latest_src_10009.home_state_latest + , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy + , users_latest_src_10009.home_state_latest AS user__home_state_latest + , users_latest_src_10009.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10009 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user +) subq_3 +GROUP BY + subq_3.listing__is_lux_latest + , subq_3.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql new file mode 100644 index 0000000000..7f093b6070 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql @@ -0,0 +1,14 @@ +-- Join Standard Outputs +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listings_latest_src_10005.is_lux AS listing__is_lux_latest + , users_latest_src_10009.home_state_latest AS user__home_state_latest +FROM ***************************.dim_listings_latest listings_latest_src_10005 +FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10009 +ON + listings_latest_src_10005.user_id = users_latest_src_10009.user_id +GROUP BY + listings_latest_src_10005.is_lux + , users_latest_src_10009.home_state_latest diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 245d744540..f477645da3 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_16.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 Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index b60ff25331..070f4444b9 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT 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 Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 7fd3032459..9d17d27426 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_13.metric_time__extract_dow , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql index 3a967f282f..01ce251cdf 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__extract_dow , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql index f0da22acac..9c69a8dd8b 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- 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 diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql index 873beed5f6..2f965192ba 100644 --- a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- 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 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql index fc804c3d2b..97f0946ad6 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- 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 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql index 552b4dc805..d2cebbcf57 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- 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 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql index ce7231f3da..62c4d422d7 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql @@ -69,62 +69,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_0 WHERE listing__country_latest = 'us' ) subq_1 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql index ec0d94dac2..53c7bf823f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_3 WHERE listing__country_latest = 'us' GROUP BY diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql index c4110473ff..4a00c4a466 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql @@ -1,44 +1,44 @@ -- Compute Metrics via Expressions SELECT - subq_10.is_instant + subq_10.booking__is_instant , subq_10.bookings FROM ( -- Aggregate Measures SELECT - subq_9.is_instant + subq_9.booking__is_instant , SUM(subq_9.bookings) AS bookings FROM ( -- Pass Only Elements: - -- ['bookings', 'is_instant'] + -- ['bookings', 'booking__is_instant'] SELECT - subq_8.is_instant + subq_8.booking__is_instant , subq_8.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_7.is_instant + subq_7.booking__is_instant , subq_7.listing__country_latest , subq_7.bookings FROM ( -- Pass Only Elements: - -- ['bookings', 'is_instant', 'listing__country_latest'] + -- ['bookings', 'booking__is_instant', 'listing__country_latest'] SELECT - subq_6.is_instant + subq_6.booking__is_instant , subq_6.listing__country_latest , subq_6.bookings FROM ( -- Join Standard Outputs SELECT subq_2.listing AS listing - , subq_2.is_instant AS is_instant + , 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', 'is_instant', 'listing'] + -- ['bookings', 'booking__is_instant', 'listing'] SELECT subq_1.listing - , subq_1.is_instant + , subq_1.booking__is_instant , subq_1.bookings FROM ( -- Metric Time Dimension 'ds' @@ -316,62 +316,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_3 ) subq_4 ) subq_5 @@ -383,5 +383,5 @@ FROM ( ) subq_8 ) subq_9 GROUP BY - subq_9.is_instant + subq_9.booking__is_instant ) subq_10 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql index 29bb79a181..d00b32fb24 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql @@ -1,35 +1,35 @@ -- Constrain Output with WHERE -- Pass Only Elements: --- ['bookings', 'is_instant'] +-- ['bookings', 'booking__is_instant'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - is_instant + booking__is_instant , SUM(bookings) AS bookings FROM ( -- Join Standard Outputs -- Pass Only Elements: - -- ['bookings', 'is_instant', 'listing__country_latest'] + -- ['bookings', 'booking__is_instant', 'listing__country_latest'] SELECT - subq_13.is_instant AS is_instant - , listings_latest_src_10004.country AS listing__country_latest + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_10005.country AS listing__country_latest , subq_13.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' -- Pass Only Elements: - -- ['bookings', 'is_instant', 'listing'] + -- ['bookings', 'booking__is_instant', 'listing'] SELECT listing_id AS listing - , is_instant + , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_13 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_13.listing = listings_latest_src_10004.listing_id + subq_13.listing = listings_latest_src_10005.listing_id ) subq_18 WHERE listing__country_latest = 'us' GROUP BY - is_instant + booking__is_instant diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql index 82d0454072..7a5e1b4b86 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql @@ -142,87 +142,87 @@ FROM ( SELECT 1 AS bookings , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_10015.booking_value - , bookings_source_src_10015.guest_id AS bookers - , bookings_source_src_10015.booking_value AS average_booking_value - , bookings_source_src_10015.booking_value AS booking_payments - , bookings_source_src_10015.is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy - , bookings_source_src_10015.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_10015.listing_id AS listing - , bookings_source_src_10015.guest_id AS guest - , bookings_source_src_10015.host_id AS host - , bookings_source_src_10015.guest_id AS user - , bookings_source_src_10015.listing_id AS booking__listing - , bookings_source_src_10015.guest_id AS booking__guest - , bookings_source_src_10015.host_id AS booking__host - , bookings_source_src_10015.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_10015 + , bookings_source_src_10017.booking_value + , bookings_source_src_10017.guest_id AS bookers + , bookings_source_src_10017.booking_value AS average_booking_value + , bookings_source_src_10017.booking_value AS booking_payments + , bookings_source_src_10017.is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy + , bookings_source_src_10017.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10017.listing_id AS listing + , bookings_source_src_10017.guest_id AS guest + , bookings_source_src_10017.host_id AS host + , bookings_source_src_10017.guest_id AS user + , bookings_source_src_10017.listing_id AS booking__listing + , bookings_source_src_10017.guest_id AS booking__guest + , bookings_source_src_10017.host_id AS booking__host + , bookings_source_src_10017.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_0 ) subq_1 ) subq_2 @@ -237,60 +237,60 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'listings' SELECT - listings_src_10017.active_from AS window_start__day - , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week - , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month - , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter - , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year - , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month - , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS window_start__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy - , listings_src_10017.active_to AS window_end__day - , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week - , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month - , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter - , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year - , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month - , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS window_end__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy - , listings_src_10017.country - , listings_src_10017.is_lux - , listings_src_10017.capacity - , listings_src_10017.active_from AS listing__window_start__day - , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week - , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month - , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter - , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year - , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month - , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS listing__window_start__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy - , listings_src_10017.active_to AS listing__window_end__day - , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week - , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month - , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter - , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year - , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month - , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS listing__window_end__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy - , listings_src_10017.country AS listing__country - , listings_src_10017.is_lux AS listing__is_lux - , listings_src_10017.capacity AS listing__capacity - , listings_src_10017.listing_id AS listing - , listings_src_10017.user_id AS user - , listings_src_10017.user_id AS listing__user - FROM ***************************.dim_listings listings_src_10017 + listings_src_10019.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10019.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10019.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10019.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10019.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10019.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_from) AS window_start__extract_month + , EXTRACT(day FROM listings_src_10019.active_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_from) AS window_start__extract_doy + , listings_src_10019.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10019.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10019.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10019.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10019.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10019.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_to) AS window_end__extract_month + , EXTRACT(day FROM listings_src_10019.active_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_to) AS window_end__extract_doy + , listings_src_10019.country + , listings_src_10019.is_lux + , listings_src_10019.capacity + , listings_src_10019.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10019.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10019.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10019.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10019.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10019.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_from) AS listing__window_start__extract_month + , EXTRACT(day FROM listings_src_10019.active_from) AS listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_from) AS listing__window_start__extract_doy + , listings_src_10019.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10019.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10019.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10019.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10019.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10019.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_to) AS listing__window_end__extract_month + , EXTRACT(day FROM listings_src_10019.active_to) AS listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_to) AS listing__window_end__extract_doy + , listings_src_10019.country AS listing__country + , listings_src_10019.is_lux AS listing__is_lux + , listings_src_10019.capacity AS listing__capacity + , listings_src_10019.listing_id AS listing + , listings_src_10019.user_id AS user + , listings_src_10019.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10019 ) subq_3 ) subq_4 ON diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql index db1199fc2e..662445e5ef 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql @@ -12,7 +12,7 @@ FROM ( -- ['bookings', 'listing__capacity', 'metric_time__day'] SELECT subq_12.metric_time__day AS metric_time__day - , listings_src_10017.capacity AS listing__capacity + , listings_src_10019.capacity AS listing__capacity , subq_12.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' @@ -23,21 +23,21 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_10015 + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_12 LEFT OUTER JOIN - ***************************.dim_listings listings_src_10017 + ***************************.dim_listings listings_src_10019 ON ( - subq_12.listing = listings_src_10017.listing_id + subq_12.listing = listings_src_10019.listing_id ) AND ( ( - subq_12.metric_time__day >= listings_src_10017.active_from + subq_12.metric_time__day >= listings_src_10019.active_from ) AND ( ( - subq_12.metric_time__day < listings_src_10017.active_to + subq_12.metric_time__day < listings_src_10019.active_to ) OR ( - listings_src_10017.active_to IS NULL + listings_src_10019.active_to IS NULL ) ) ) diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql index cf23763319..7115d3825a 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql @@ -87,62 +87,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_0 ) subq_1 ) subq_2 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql index f7932552c3..2c5690447e 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql @@ -11,7 +11,7 @@ FROM ( SELECT country AS listing__country_latest , 1 AS listings - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_6 GROUP BY listing__country_latest diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql index 70ed3cd24c..169e346efc 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql @@ -3,7 +3,7 @@ SELECT subq_29.metric_time__day , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr FROM ( - -- Combine Metrics + -- 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 @@ -328,62 +328,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_3 ) subq_4 ) subq_5 @@ -717,62 +717,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_15 ) subq_16 ) subq_17 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql index 0b555b1430..5581a37a67 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr FROM ( - -- Combine Metrics + -- Combine Aggregated Outputs SELECT COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day) AS metric_time__day , MAX(subq_41.average_booking_value) AS average_booking_value @@ -24,13 +24,13 @@ FROM ( -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] SELECT DATE_TRUNC('day', bookings_source_src_10001.ds) AS metric_time__day - , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest , bookings_source_src_10001.booking_value AS average_booking_value FROM ***************************.fct_bookings bookings_source_src_10001 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - bookings_source_src_10001.listing_id = listings_latest_src_10004.listing_id + bookings_source_src_10001.listing_id = listings_latest_src_10005.listing_id ) subq_37 WHERE listing__is_lux_latest GROUP BY @@ -51,7 +51,7 @@ FROM ( -- ['bookings', 'listing__is_lux_latest', 'metric_time__day'] SELECT subq_44.metric_time__day AS metric_time__day - , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest , subq_44.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' @@ -65,9 +65,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_10001 ) subq_44 LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_10004 + ***************************.dim_listings_latest listings_latest_src_10005 ON - subq_44.listing = listings_latest_src_10004.listing_id + subq_44.listing = listings_latest_src_10005.listing_id ) subq_49 WHERE listing__is_lux_latest GROUP BY diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql index 8504a01af1..81907f7e40 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql @@ -3,7 +3,7 @@ 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 FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql index 77f5d693df..2d2b5a142c 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -3,7 +3,7 @@ SELECT metric_time__day , CAST(booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( - -- Combine Metrics + -- 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 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 91fcb63ee0..cbc1f426c2 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -2,7 +2,7 @@ SELECT CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.listings, 0) AS DOUBLE) AS bookings_per_listing FROM ( - -- Combine Metrics + -- Combine Aggregated Outputs SELECT MAX(subq_4.bookings) AS bookings , MAX(subq_9.listings) AS listings @@ -304,62 +304,62 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_5 ) subq_6 ) subq_7 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 8a1096e90f..1e16df6c0d 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- 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 @@ -22,5 +22,5 @@ CROSS JOIN ( -- Compute Metrics via Expressions SELECT SUM(1) AS listings - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_20 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql index 6b26e02a73..2bbff5684b 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql @@ -132,87 +132,87 @@ FROM ( SELECT 1 AS bookings , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_10015.booking_value - , bookings_source_src_10015.guest_id AS bookers - , bookings_source_src_10015.booking_value AS average_booking_value - , bookings_source_src_10015.booking_value AS booking_payments - , bookings_source_src_10015.is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy - , bookings_source_src_10015.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_10015.listing_id AS listing - , bookings_source_src_10015.guest_id AS guest - , bookings_source_src_10015.host_id AS host - , bookings_source_src_10015.guest_id AS user - , bookings_source_src_10015.listing_id AS booking__listing - , bookings_source_src_10015.guest_id AS booking__guest - , bookings_source_src_10015.host_id AS booking__host - , bookings_source_src_10015.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_10015 + , bookings_source_src_10017.booking_value + , bookings_source_src_10017.guest_id AS bookers + , bookings_source_src_10017.booking_value AS average_booking_value + , bookings_source_src_10017.booking_value AS booking_payments + , bookings_source_src_10017.is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy + , bookings_source_src_10017.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10017.listing_id AS listing + , bookings_source_src_10017.guest_id AS guest + , bookings_source_src_10017.host_id AS host + , bookings_source_src_10017.guest_id AS user + , bookings_source_src_10017.listing_id AS booking__listing + , bookings_source_src_10017.guest_id AS booking__guest + , bookings_source_src_10017.host_id AS booking__host + , bookings_source_src_10017.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_0 ) subq_1 ) subq_2 @@ -295,60 +295,60 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'listings' SELECT - listings_src_10017.active_from AS window_start__day - , DATE_TRUNC('week', listings_src_10017.active_from) AS window_start__week - , DATE_TRUNC('month', listings_src_10017.active_from) AS window_start__month - , DATE_TRUNC('quarter', listings_src_10017.active_from) AS window_start__quarter - , DATE_TRUNC('year', listings_src_10017.active_from) AS window_start__year - , EXTRACT(year FROM listings_src_10017.active_from) AS window_start__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_from) AS window_start__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_from) AS window_start__extract_month - , EXTRACT(day FROM listings_src_10017.active_from) AS window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS window_start__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_from) AS window_start__extract_doy - , listings_src_10017.active_to AS window_end__day - , DATE_TRUNC('week', listings_src_10017.active_to) AS window_end__week - , DATE_TRUNC('month', listings_src_10017.active_to) AS window_end__month - , DATE_TRUNC('quarter', listings_src_10017.active_to) AS window_end__quarter - , DATE_TRUNC('year', listings_src_10017.active_to) AS window_end__year - , EXTRACT(year FROM listings_src_10017.active_to) AS window_end__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_to) AS window_end__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_to) AS window_end__extract_month - , EXTRACT(day FROM listings_src_10017.active_to) AS window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS window_end__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_to) AS window_end__extract_doy - , listings_src_10017.country - , listings_src_10017.is_lux - , listings_src_10017.capacity - , listings_src_10017.active_from AS listing__window_start__day - , DATE_TRUNC('week', listings_src_10017.active_from) AS listing__window_start__week - , DATE_TRUNC('month', listings_src_10017.active_from) AS listing__window_start__month - , DATE_TRUNC('quarter', listings_src_10017.active_from) AS listing__window_start__quarter - , DATE_TRUNC('year', listings_src_10017.active_from) AS listing__window_start__year - , EXTRACT(year FROM listings_src_10017.active_from) AS listing__window_start__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_from) AS listing__window_start__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_from) AS listing__window_start__extract_month - , EXTRACT(day FROM listings_src_10017.active_from) AS listing__window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_from) AS listing__window_start__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_from) AS listing__window_start__extract_doy - , listings_src_10017.active_to AS listing__window_end__day - , DATE_TRUNC('week', listings_src_10017.active_to) AS listing__window_end__week - , DATE_TRUNC('month', listings_src_10017.active_to) AS listing__window_end__month - , DATE_TRUNC('quarter', listings_src_10017.active_to) AS listing__window_end__quarter - , DATE_TRUNC('year', listings_src_10017.active_to) AS listing__window_end__year - , EXTRACT(year FROM listings_src_10017.active_to) AS listing__window_end__extract_year - , EXTRACT(quarter FROM listings_src_10017.active_to) AS listing__window_end__extract_quarter - , EXTRACT(month FROM listings_src_10017.active_to) AS listing__window_end__extract_month - , EXTRACT(day FROM listings_src_10017.active_to) AS listing__window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_src_10017.active_to) AS listing__window_end__extract_dow - , EXTRACT(doy FROM listings_src_10017.active_to) AS listing__window_end__extract_doy - , listings_src_10017.country AS listing__country - , listings_src_10017.is_lux AS listing__is_lux - , listings_src_10017.capacity AS listing__capacity - , listings_src_10017.listing_id AS listing - , listings_src_10017.user_id AS user - , listings_src_10017.user_id AS listing__user - FROM ***************************.dim_listings listings_src_10017 + listings_src_10019.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_10019.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_10019.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_10019.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_10019.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_10019.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_from) AS window_start__extract_month + , EXTRACT(day FROM listings_src_10019.active_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_from) AS window_start__extract_doy + , listings_src_10019.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_10019.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_10019.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_10019.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_10019.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_10019.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_to) AS window_end__extract_month + , EXTRACT(day FROM listings_src_10019.active_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_to) AS window_end__extract_doy + , listings_src_10019.country + , listings_src_10019.is_lux + , listings_src_10019.capacity + , listings_src_10019.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_10019.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_10019.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_10019.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_10019.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_10019.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_from) AS listing__window_start__extract_month + , EXTRACT(day FROM listings_src_10019.active_from) AS listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_from) AS listing__window_start__extract_doy + , listings_src_10019.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_10019.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_10019.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_10019.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_10019.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_10019.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_10019.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_10019.active_to) AS listing__window_end__extract_month + , EXTRACT(day FROM listings_src_10019.active_to) AS listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_10019.active_to) AS listing__window_end__extract_doy + , listings_src_10019.country AS listing__country + , listings_src_10019.is_lux AS listing__is_lux + , listings_src_10019.capacity AS listing__capacity + , listings_src_10019.listing_id AS listing + , listings_src_10019.user_id AS user + , listings_src_10019.user_id AS listing__user + FROM ***************************.dim_listings listings_src_10019 ) subq_3 LEFT OUTER JOIN ( -- Pass Only Elements: @@ -406,32 +406,32 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT - DATE_TRUNC('day', users_latest_src_10021.ds) AS ds__day - , DATE_TRUNC('week', users_latest_src_10021.ds) AS ds__week - , DATE_TRUNC('month', users_latest_src_10021.ds) AS ds__month - , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS ds__quarter - , DATE_TRUNC('year', users_latest_src_10021.ds) AS ds__year - , EXTRACT(year FROM users_latest_src_10021.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_latest_src_10021.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_latest_src_10021.ds) AS ds__extract_month - , EXTRACT(day FROM users_latest_src_10021.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10021.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_latest_src_10021.ds) AS ds__extract_doy - , users_latest_src_10021.home_state_latest - , DATE_TRUNC('day', users_latest_src_10021.ds) AS user__ds__day - , DATE_TRUNC('week', users_latest_src_10021.ds) AS user__ds__week - , DATE_TRUNC('month', users_latest_src_10021.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_latest_src_10021.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_latest_src_10021.ds) AS user__ds__year - , EXTRACT(year FROM users_latest_src_10021.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_latest_src_10021.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_latest_src_10021.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_latest_src_10021.ds) AS user__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10021.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_latest_src_10021.ds) AS user__ds__extract_doy - , users_latest_src_10021.home_state_latest AS user__home_state_latest - , users_latest_src_10021.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_10021 + DATE_TRUNC('day', users_latest_src_10023.ds) AS ds__day + , DATE_TRUNC('week', users_latest_src_10023.ds) AS ds__week + , DATE_TRUNC('month', users_latest_src_10023.ds) AS ds__month + , DATE_TRUNC('quarter', users_latest_src_10023.ds) AS ds__quarter + , DATE_TRUNC('year', users_latest_src_10023.ds) AS ds__year + , EXTRACT(year FROM users_latest_src_10023.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10023.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10023.ds) AS ds__extract_month + , EXTRACT(day FROM users_latest_src_10023.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10023.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10023.ds) AS ds__extract_doy + , users_latest_src_10023.home_state_latest + , DATE_TRUNC('day', users_latest_src_10023.ds) AS user__ds__day + , DATE_TRUNC('week', users_latest_src_10023.ds) AS user__ds__week + , DATE_TRUNC('month', users_latest_src_10023.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_latest_src_10023.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_latest_src_10023.ds) AS user__ds__year + , EXTRACT(year FROM users_latest_src_10023.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_latest_src_10023.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_latest_src_10023.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_latest_src_10023.ds) AS user__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10023.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_latest_src_10023.ds) AS user__ds__extract_doy + , users_latest_src_10023.home_state_latest AS user__home_state_latest + , users_latest_src_10023.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10023 ) subq_4 ) subq_5 ON diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql index aa2ad14d34..afba0439d0 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql @@ -16,22 +16,22 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_10015 + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_13 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] SELECT - listings_src_10017.active_from AS window_start__day - , listings_src_10017.active_to AS window_end__day - , listings_src_10017.listing_id AS listing - , users_latest_src_10021.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings listings_src_10017 + listings_src_10019.active_from AS window_start__day + , listings_src_10019.active_to AS window_end__day + , listings_src_10019.listing_id AS listing + , users_latest_src_10023.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings listings_src_10019 LEFT OUTER JOIN - ***************************.dim_users_latest users_latest_src_10021 + ***************************.dim_users_latest users_latest_src_10023 ON - listings_src_10017.user_id = users_latest_src_10021.user_id + listings_src_10019.user_id = users_latest_src_10023.user_id ) subq_18 ON ( diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql index 2f8712914a..5e879e0c1c 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql @@ -132,87 +132,87 @@ FROM ( SELECT 1 AS bookings , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_10015.booking_value - , bookings_source_src_10015.guest_id AS bookers - , bookings_source_src_10015.booking_value AS average_booking_value - , bookings_source_src_10015.booking_value AS booking_payments - , bookings_source_src_10015.is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS paid_at__extract_doy - , bookings_source_src_10015.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_10015.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_10015.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_10015.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_10015.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_10015.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_10015.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_10015.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_10015.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_10015.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_10015.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_10015.listing_id AS listing - , bookings_source_src_10015.guest_id AS guest - , bookings_source_src_10015.host_id AS host - , bookings_source_src_10015.guest_id AS user - , bookings_source_src_10015.listing_id AS booking__listing - , bookings_source_src_10015.guest_id AS booking__guest - , bookings_source_src_10015.host_id AS booking__host - , bookings_source_src_10015.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_10015 + , bookings_source_src_10017.booking_value + , bookings_source_src_10017.guest_id AS bookers + , bookings_source_src_10017.booking_value AS average_booking_value + , bookings_source_src_10017.booking_value AS booking_payments + , bookings_source_src_10017.is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy + , bookings_source_src_10017.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_10017.listing_id AS listing + , bookings_source_src_10017.guest_id AS guest + , bookings_source_src_10017.host_id AS host + , bookings_source_src_10017.guest_id AS user + , bookings_source_src_10017.listing_id AS booking__listing + , bookings_source_src_10017.guest_id AS booking__guest + , bookings_source_src_10017.host_id AS booking__host + , bookings_source_src_10017.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_0 ) subq_1 ) subq_2 @@ -259,10 +259,10 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'lux_listing_mapping' SELECT - lux_listing_mapping_src_10018.listing_id AS listing - , lux_listing_mapping_src_10018.lux_listing_id AS lux_listing - , lux_listing_mapping_src_10018.lux_listing_id AS listing__lux_listing - FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + lux_listing_mapping_src_10020.listing_id AS listing + , lux_listing_mapping_src_10020.lux_listing_id AS lux_listing + , lux_listing_mapping_src_10020.lux_listing_id AS listing__lux_listing + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10020 ) subq_3 LEFT OUTER JOIN ( -- Pass Only Elements: @@ -364,54 +364,54 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'lux_listings' SELECT - lux_listings_src_10019.valid_from AS window_start__day - , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS window_start__week - , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS window_start__month - , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS window_start__quarter - , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS window_start__year - , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS window_start__extract_year - , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS window_start__extract_quarter - , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS window_start__extract_month - , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_from) AS window_start__extract_dow - , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS window_start__extract_doy - , lux_listings_src_10019.valid_to AS window_end__day - , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS window_end__week - , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS window_end__month - , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS window_end__quarter - , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS window_end__year - , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS window_end__extract_year - , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS window_end__extract_quarter - , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS window_end__extract_month - , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_to) AS window_end__extract_dow - , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS window_end__extract_doy - , lux_listings_src_10019.is_confirmed_lux - , lux_listings_src_10019.valid_from AS lux_listing__window_start__day - , DATE_TRUNC('week', lux_listings_src_10019.valid_from) AS lux_listing__window_start__week - , DATE_TRUNC('month', lux_listings_src_10019.valid_from) AS lux_listing__window_start__month - , DATE_TRUNC('quarter', lux_listings_src_10019.valid_from) AS lux_listing__window_start__quarter - , DATE_TRUNC('year', lux_listings_src_10019.valid_from) AS lux_listing__window_start__year - , EXTRACT(year FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_year - , EXTRACT(quarter FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_quarter - , EXTRACT(month FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_month - , EXTRACT(day FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_day - , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_dow - , EXTRACT(doy FROM lux_listings_src_10019.valid_from) AS lux_listing__window_start__extract_doy - , lux_listings_src_10019.valid_to AS lux_listing__window_end__day - , DATE_TRUNC('week', lux_listings_src_10019.valid_to) AS lux_listing__window_end__week - , DATE_TRUNC('month', lux_listings_src_10019.valid_to) AS lux_listing__window_end__month - , DATE_TRUNC('quarter', lux_listings_src_10019.valid_to) AS lux_listing__window_end__quarter - , DATE_TRUNC('year', lux_listings_src_10019.valid_to) AS lux_listing__window_end__year - , EXTRACT(year FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_year - , EXTRACT(quarter FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_quarter - , EXTRACT(month FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_month - , EXTRACT(day FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_day - , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_dow - , EXTRACT(doy FROM lux_listings_src_10019.valid_to) AS lux_listing__window_end__extract_doy - , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux - , lux_listings_src_10019.lux_listing_id AS lux_listing - FROM ***************************.dim_lux_listings lux_listings_src_10019 + lux_listings_src_10021.valid_from AS window_start__day + , DATE_TRUNC('week', lux_listings_src_10021.valid_from) AS window_start__week + , DATE_TRUNC('month', lux_listings_src_10021.valid_from) AS window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10021.valid_from) AS window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10021.valid_from) AS window_start__year + , EXTRACT(year FROM lux_listings_src_10021.valid_from) AS window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10021.valid_from) AS window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10021.valid_from) AS window_start__extract_month + , EXTRACT(day FROM lux_listings_src_10021.valid_from) AS window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_from) AS window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10021.valid_from) AS window_start__extract_doy + , lux_listings_src_10021.valid_to AS window_end__day + , DATE_TRUNC('week', lux_listings_src_10021.valid_to) AS window_end__week + , DATE_TRUNC('month', lux_listings_src_10021.valid_to) AS window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10021.valid_to) AS window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10021.valid_to) AS window_end__year + , EXTRACT(year FROM lux_listings_src_10021.valid_to) AS window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10021.valid_to) AS window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10021.valid_to) AS window_end__extract_month + , EXTRACT(day FROM lux_listings_src_10021.valid_to) AS window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_to) AS window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10021.valid_to) AS window_end__extract_doy + , lux_listings_src_10021.is_confirmed_lux + , lux_listings_src_10021.valid_from AS lux_listing__window_start__day + , DATE_TRUNC('week', lux_listings_src_10021.valid_from) AS lux_listing__window_start__week + , DATE_TRUNC('month', lux_listings_src_10021.valid_from) AS lux_listing__window_start__month + , DATE_TRUNC('quarter', lux_listings_src_10021.valid_from) AS lux_listing__window_start__quarter + , DATE_TRUNC('year', lux_listings_src_10021.valid_from) AS lux_listing__window_start__year + , EXTRACT(year FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_month + , EXTRACT(day FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_doy + , lux_listings_src_10021.valid_to AS lux_listing__window_end__day + , DATE_TRUNC('week', lux_listings_src_10021.valid_to) AS lux_listing__window_end__week + , DATE_TRUNC('month', lux_listings_src_10021.valid_to) AS lux_listing__window_end__month + , DATE_TRUNC('quarter', lux_listings_src_10021.valid_to) AS lux_listing__window_end__quarter + , DATE_TRUNC('year', lux_listings_src_10021.valid_to) AS lux_listing__window_end__year + , EXTRACT(year FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_month + , EXTRACT(day FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_day + , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_doy + , lux_listings_src_10021.is_confirmed_lux AS lux_listing__is_confirmed_lux + , lux_listings_src_10021.lux_listing_id AS lux_listing + FROM ***************************.dim_lux_listings lux_listings_src_10021 ) subq_4 ) subq_5 ON diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql index add7e259ab..16470814e6 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql @@ -16,7 +16,7 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_10015 + FROM ***************************.fct_bookings bookings_source_src_10017 ) subq_13 LEFT OUTER JOIN ( -- Join Standard Outputs @@ -26,15 +26,15 @@ LEFT OUTER JOIN ( -- 'lux_listing__window_end__day', -- 'listing'] SELECT - lux_listings_src_10019.valid_from AS lux_listing__window_start__day - , lux_listings_src_10019.valid_to AS lux_listing__window_end__day - , lux_listing_mapping_src_10018.listing_id AS listing - , lux_listings_src_10019.is_confirmed_lux AS lux_listing__is_confirmed_lux - FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10018 + lux_listings_src_10021.valid_from AS lux_listing__window_start__day + , lux_listings_src_10021.valid_to AS lux_listing__window_end__day + , lux_listing_mapping_src_10020.listing_id AS listing + , lux_listings_src_10021.is_confirmed_lux AS lux_listing__is_confirmed_lux + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10020 LEFT OUTER JOIN - ***************************.dim_lux_listings lux_listings_src_10019 + ***************************.dim_lux_listings lux_listings_src_10021 ON - lux_listing_mapping_src_10018.lux_listing_id = lux_listings_src_10019.lux_listing_id + lux_listing_mapping_src_10020.lux_listing_id = lux_listings_src_10021.lux_listing_id ) subq_18 ON ( diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql index f07aa049e6..499b9f8c12 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql @@ -93,55 +93,55 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'account_month_txns' SELECT - account_month_txns_src_10010.txn_count - , DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_10010.ds) AS ds__day - , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS ds__week - , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS ds__month - , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS ds__quarter - , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS ds__year - , EXTRACT(year FROM account_month_txns_src_10010.ds) AS ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_10010.ds) AS ds__extract_month - , EXTRACT(day FROM account_month_txns_src_10010.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds) AS ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS ds__extract_doy - , account_month_txns_src_10010.account_month - , DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_10010.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_10010.ds) AS account_id__ds__day - , DATE_TRUNC('week', account_month_txns_src_10010.ds) AS account_id__ds__week - , DATE_TRUNC('month', account_month_txns_src_10010.ds) AS account_id__ds__month - , DATE_TRUNC('quarter', account_month_txns_src_10010.ds) AS account_id__ds__quarter - , DATE_TRUNC('year', account_month_txns_src_10010.ds) AS account_id__ds__year - , EXTRACT(year FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_month - , EXTRACT(day FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_10010.ds) AS account_id__ds__extract_doy - , account_month_txns_src_10010.account_month AS account_id__account_month - , account_month_txns_src_10010.account_id - FROM ***************************.account_month_txns account_month_txns_src_10010 + account_month_txns_src_10012.txn_count + , DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_10012.ds) AS ds__day + , DATE_TRUNC('week', account_month_txns_src_10012.ds) AS ds__week + , DATE_TRUNC('month', account_month_txns_src_10012.ds) AS ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10012.ds) AS ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10012.ds) AS ds__year + , EXTRACT(year FROM account_month_txns_src_10012.ds) AS ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10012.ds) AS ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10012.ds) AS ds__extract_month + , EXTRACT(day FROM account_month_txns_src_10012.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds) AS ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10012.ds) AS ds__extract_doy + , account_month_txns_src_10012.account_month + , DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_10012.ds) AS account_id__ds__day + , DATE_TRUNC('week', account_month_txns_src_10012.ds) AS account_id__ds__week + , DATE_TRUNC('month', account_month_txns_src_10012.ds) AS account_id__ds__month + , DATE_TRUNC('quarter', account_month_txns_src_10012.ds) AS account_id__ds__quarter + , DATE_TRUNC('year', account_month_txns_src_10012.ds) AS account_id__ds__year + , EXTRACT(year FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_month + , EXTRACT(day FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_doy + , account_month_txns_src_10012.account_month AS account_id__account_month + , account_month_txns_src_10012.account_id + FROM ***************************.account_month_txns account_month_txns_src_10012 ) subq_0 ) subq_1 ) subq_2 @@ -212,48 +212,48 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'bridge_table' SELECT - bridge_table_src_10011.extra_dim - , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS ds_partitioned__extract_doy - , bridge_table_src_10011.extra_dim AS account_id__extra_dim - , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , bridge_table_src_10011.extra_dim AS bridge_account__extra_dim - , DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_10011.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy - , bridge_table_src_10011.account_id - , bridge_table_src_10011.customer_id - , bridge_table_src_10011.customer_id AS account_id__customer_id - , bridge_table_src_10011.account_id AS bridge_account__account_id - , bridge_table_src_10011.customer_id AS bridge_account__customer_id - FROM ***************************.bridge_table bridge_table_src_10011 + bridge_table_src_10013.extra_dim + , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_doy + , bridge_table_src_10013.extra_dim AS account_id__extra_dim + , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , bridge_table_src_10013.extra_dim AS bridge_account__extra_dim + , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy + , bridge_table_src_10013.account_id + , bridge_table_src_10013.customer_id + , bridge_table_src_10013.customer_id AS account_id__customer_id + , bridge_table_src_10013.account_id AS bridge_account__account_id + , bridge_table_src_10013.customer_id AS bridge_account__customer_id + FROM ***************************.bridge_table bridge_table_src_10013 ) subq_3 LEFT OUTER JOIN ( -- Pass Only Elements: @@ -315,34 +315,34 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'customer_table' SELECT - customer_table_src_10013.customer_name - , customer_table_src_10013.customer_atomic_weight - , DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS ds_partitioned__extract_doy - , customer_table_src_10013.customer_name AS customer_id__customer_name - , customer_table_src_10013.customer_atomic_weight AS customer_id__customer_atomic_weight - , DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__day - , DATE_TRUNC('week', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__week - , DATE_TRUNC('month', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__month - , DATE_TRUNC('quarter', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__quarter - , DATE_TRUNC('year', customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__year - , EXTRACT(year FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_month - , EXTRACT(day FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM customer_table_src_10013.ds_partitioned) AS customer_id__ds_partitioned__extract_doy - , customer_table_src_10013.customer_id - FROM ***************************.customer_table customer_table_src_10013 + customer_table_src_10015.customer_name + , customer_table_src_10015.customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_10015.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10015.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10015.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10015.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10015.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_doy + , customer_table_src_10015.customer_name AS customer_id__customer_name + , customer_table_src_10015.customer_atomic_weight AS customer_id__customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__year + , EXTRACT(year FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_doy + , customer_table_src_10015.customer_id + FROM ***************************.customer_table customer_table_src_10015 ) subq_4 ) subq_5 ON diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql index 8a42052413..65d688b745 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql @@ -5,31 +5,31 @@ -- Compute Metrics via Expressions SELECT subq_18.customer_id__customer_name AS account_id__customer_id__customer_name - , SUM(account_month_txns_src_10010.txn_count) AS txn_count -FROM ***************************.account_month_txns account_month_txns_src_10010 + , SUM(account_month_txns_src_10012.txn_count) AS txn_count +FROM ***************************.account_month_txns account_month_txns_src_10012 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] SELECT - DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) AS ds_partitioned__day - , bridge_table_src_10011.account_id AS account_id - , customer_table_src_10013.customer_name AS customer_id__customer_name - FROM ***************************.bridge_table bridge_table_src_10011 + DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__day + , bridge_table_src_10013.account_id AS account_id + , customer_table_src_10015.customer_name AS customer_id__customer_name + FROM ***************************.bridge_table bridge_table_src_10013 LEFT OUTER JOIN - ***************************.customer_table customer_table_src_10013 + ***************************.customer_table customer_table_src_10015 ON ( - bridge_table_src_10011.customer_id = customer_table_src_10013.customer_id + bridge_table_src_10013.customer_id = customer_table_src_10015.customer_id ) AND ( - DATE_TRUNC('day', bridge_table_src_10011.ds_partitioned) = DATE_TRUNC('day', customer_table_src_10013.ds_partitioned) + DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) = DATE_TRUNC('day', customer_table_src_10015.ds_partitioned) ) ) subq_18 ON ( - account_month_txns_src_10010.account_id = subq_18.account_id + account_month_txns_src_10012.account_id = subq_18.account_id ) AND ( - DATE_TRUNC('day', account_month_txns_src_10010.ds_partitioned) = subq_18.ds_partitioned__day + DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) = subq_18.ds_partitioned__day ) GROUP BY subq_18.customer_id__customer_name diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql index 6231b02dc1..657579fe50 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- Combine Aggregated Outputs SELECT MAX(subq_5.bookings) AS bookings , MAX(subq_11.listings) AS listings @@ -473,62 +473,62 @@ CROSS JOIN ( -- Read Elements From Semantic Model 'listings_latest' SELECT 1 AS listings - , listings_latest_src_10004.capacity AS largest_listing - , listings_latest_src_10004.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy - , listings_latest_src_10004.country AS country_latest - , listings_latest_src_10004.is_lux AS is_lux_latest - , listings_latest_src_10004.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy - , listings_latest_src_10004.country AS listing__country_latest - , listings_latest_src_10004.is_lux AS listing__is_lux_latest - , listings_latest_src_10004.capacity AS listing__capacity_latest - , listings_latest_src_10004.listing_id AS listing - , listings_latest_src_10004.user_id AS user - , listings_latest_src_10004.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_10004 + , listings_latest_src_10005.capacity AS largest_listing + , listings_latest_src_10005.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy + , listings_latest_src_10005.country AS country_latest + , listings_latest_src_10005.is_lux AS is_lux_latest + , listings_latest_src_10005.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10005.country AS listing__country_latest + , listings_latest_src_10005.is_lux AS listing__is_lux_latest + , listings_latest_src_10005.capacity AS listing__capacity_latest + , listings_latest_src_10005.listing_id AS listing + , listings_latest_src_10005.user_id AS user + , listings_latest_src_10005.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10005 ) subq_6 ) subq_7 WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql index 5ed649f283..3c0ea8fcbb 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Combine Metrics +-- Combine Aggregated Outputs SELECT MAX(subq_17.bookings) AS bookings , MAX(subq_23.listings) AS listings @@ -25,6 +25,6 @@ CROSS JOIN ( -- Compute Metrics via Expressions SELECT SUM(1) AS listings - FROM ***************************.dim_listings_latest listings_latest_src_10004 + FROM ***************************.dim_listings_latest listings_latest_src_10005 WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01' ) subq_23 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql index 8b9f457552..cf515d8b83 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql @@ -96,56 +96,56 @@ FROM ( -- Read Elements From Semantic Model 'id_verifications' SELECT 1 AS identity_verifications - , DATE_TRUNC('day', id_verifications_src_10003.ds) AS ds__day - , DATE_TRUNC('week', id_verifications_src_10003.ds) AS ds__week - , DATE_TRUNC('month', id_verifications_src_10003.ds) AS ds__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS ds__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds) AS ds__year - , EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy - , id_verifications_src_10003.verification_type - , DATE_TRUNC('day', id_verifications_src_10003.ds) AS verification__ds__day - , DATE_TRUNC('week', id_verifications_src_10003.ds) AS verification__ds__week - , DATE_TRUNC('month', id_verifications_src_10003.ds) AS verification__ds__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds) AS verification__ds__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds) AS verification__ds__year - , EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy - , id_verifications_src_10003.verification_type AS verification__verification_type - , id_verifications_src_10003.verification_id AS verification - , id_verifications_src_10003.user_id AS user - , id_verifications_src_10003.user_id AS verification__user - FROM ***************************.fct_id_verifications id_verifications_src_10003 + , DATE_TRUNC('day', id_verifications_src_10004.ds) AS ds__day + , DATE_TRUNC('week', id_verifications_src_10004.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_10004.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_10004.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds) AS ds__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds) AS ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_10004.verification_type + , DATE_TRUNC('day', id_verifications_src_10004.ds) AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_10004.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_10004.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_10004.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds) AS verification__ds__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds) AS verification__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds) AS verification__ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_10004.verification_type AS verification__verification_type + , id_verifications_src_10004.verification_id AS verification + , id_verifications_src_10004.user_id AS user + , id_verifications_src_10004.user_id AS verification__user + FROM ***************************.fct_id_verifications id_verifications_src_10004 ) subq_0 ) subq_1 ) subq_2 @@ -159,76 +159,76 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'users_ds_source' SELECT - DATE_TRUNC('day', users_ds_source_src_10007.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_10007.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_10007.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_10007.home_state - , DATE_TRUNC('day', users_ds_source_src_10007.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_10007.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_10007.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_10007.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.ds) AS user__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_10007.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_10007.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_10007.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_10007.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_10007.home_state AS user__home_state - , users_ds_source_src_10007.user_id AS user - FROM ***************************.dim_users users_ds_source_src_10007 + DATE_TRUNC('day', users_ds_source_src_10008.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_10008.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_10008.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_10008.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10008.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_10008.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_10008.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_10008.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_10008.home_state + , DATE_TRUNC('day', users_ds_source_src_10008.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_10008.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_10008.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_10008.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.ds) AS user__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10008.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_10008.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_10008.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_10008.home_state AS user__home_state + , users_ds_source_src_10008.user_id AS user + FROM ***************************.dim_users users_ds_source_src_10008 ) subq_3 ) subq_4 ON diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql index c15982d861..b52d743037 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql @@ -4,7 +4,7 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - users_ds_source_src_10007.home_state AS user__home_state + users_ds_source_src_10008.home_state AS user__home_state , SUM(subq_10.identity_verifications) AS identity_verifications FROM ( -- Read Elements From Semantic Model 'id_verifications' @@ -15,15 +15,15 @@ FROM ( DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day , user_id AS user , 1 AS identity_verifications - FROM ***************************.fct_id_verifications id_verifications_src_10003 + FROM ***************************.fct_id_verifications id_verifications_src_10004 ) subq_10 LEFT OUTER JOIN - ***************************.dim_users users_ds_source_src_10007 + ***************************.dim_users users_ds_source_src_10008 ON ( - subq_10.user = users_ds_source_src_10007.user_id + subq_10.user = users_ds_source_src_10008.user_id ) AND ( - subq_10.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_10007.ds_partitioned) + subq_10.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned) ) GROUP BY - users_ds_source_src_10007.home_state + users_ds_source_src_10008.home_state From c009a8417d537163941e03b385b24ab1d96ec6c0 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sat, 16 Dec 2023 10:32:15 -0700 Subject: [PATCH 17/18] change grouping to positional param for order limit test --- metricflow/test/integration/test_cases/itest_order_limit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricflow/test/integration/test_cases/itest_order_limit.yaml b/metricflow/test/integration/test_cases/itest_order_limit.yaml index 7e5af9779c..0cc563056a 100644 --- a/metricflow/test/integration/test_cases/itest_order_limit.yaml +++ b/metricflow/test/integration/test_cases/itest_order_limit.yaml @@ -69,6 +69,6 @@ integration_test: , SUM(booking_value) AS booking_value FROM {{ source_schema }}.fct_bookings GROUP BY - {{ render_date_trunc("ds", TimeGranularity.MONTH) }} + 1 ORDER BY metric_time__month DESC, booking_value From 4c9021a103375da542516a955eab005e84901a46 Mon Sep 17 00:00:00 2001 From: sarbmeetka Date: Sat, 16 Dec 2023 20:49:34 -0700 Subject: [PATCH 18/18] Fix pending test case --- .../query_output/test_cumulative_metrics.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/metricflow/test/integration/query_output/test_cumulative_metrics.py b/metricflow/test/integration/query_output/test_cumulative_metrics.py index 026c840dd1..3c6016c522 100644 --- a/metricflow/test/integration/query_output/test_cumulative_metrics.py +++ b/metricflow/test/integration/query_output/test_cumulative_metrics.py @@ -133,15 +133,19 @@ def test_cumulative_metric_with_non_adjustable_filter( it_helpers: IntegrationTestHelpers, ) -> None: """Tests a cumulative metric with a filter that cannot be adjusted to ensure all data is included.""" + + # Handle ds expression based on engine to support Trino. + first_ds_expr = f"CAST('2020-03-15' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})" + second_ds_expr = f"CAST('2020-04-30' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})" + where_constraint = f"{{{{ TimeDimension('metric_time', 'day') }}}} = {first_ds_expr} or" + where_constraint += f" {{{{ TimeDimension('metric_time', 'day') }}}} = {second_ds_expr}" + query_result = it_helpers.mf_engine.query( MetricFlowQueryRequest.create_with_random_request_id( metric_names=["trailing_2_months_revenue"], group_by_names=["metric_time"], order_by_names=["metric_time"], - where_constraint=( - "{{ TimeDimension('metric_time', 'day') }} = '2020-03-15' or " - "{{ TimeDimension('metric_time', 'day') }} = '2020-04-30'" - ), + where_constraint=where_constraint, time_constraint_end=as_datetime("2020-12-31"), ) )