diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 650408bbe8..dfa50f7e33 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -241,14 +241,13 @@ def _build_metrics_output_node( f"For {metric.type} metric: {metric_spec}, needed metrics are:\n" f"{pformat_big_objects(metric_input_specs=metric_input_specs)}" ) - join_type = SqlJoinType.FULL_OUTER if metric.type is MetricType.DERIVED else SqlJoinType.INNER compute_metrics_node = ComputeMetricsNode( parent_node=self._build_metrics_output_node( metric_specs=metric_input_specs, queried_linkable_specs=queried_linkable_specs, where_constraint=where_constraint, time_range_constraint=time_range_constraint, - combine_metrics_join_type=join_type, + combine_metrics_join_type=SqlJoinType.FULL_OUTER, ), metric_specs=[metric_spec], ) diff --git a/metricflow/test/integration/test_cases/itest_measure_constraints.yaml b/metricflow/test/integration/test_cases/itest_measure_constraints.yaml index 77725be38c..d67ffea68f 100644 --- a/metricflow/test/integration/test_cases/itest_measure_constraints.yaml +++ b/metricflow/test/integration/test_cases/itest_measure_constraints.yaml @@ -18,7 +18,7 @@ integration_test: WHERE is_instant GROUP BY ds ) a - JOIN ( + FULL OUTER JOIN ( SELECT CAST(NULLIF(MAX(booking_value), 0) AS {{ double_data_type_name }} ) AS max_booking_value , ds @@ -48,7 +48,7 @@ integration_test: WHERE listings_latest.is_lux GROUP BY fct_bookings.ds ) a - JOIN ( + FULL OUTER JOIN ( SELECT CAST(NULLIF(MAX(booking_value), 0) AS {{ double_data_type_name }} ) AS max_booking_value , ds @@ -79,7 +79,7 @@ integration_test: WHERE listings_latest.is_lux GROUP BY fct_bookings.ds ) a - JOIN ( + FULL OUTER JOIN ( SELECT CAST(NULLIF(SUM(booking_value), 0) AS {{ double_data_type_name }} ) AS booking_value , ds @@ -107,7 +107,7 @@ integration_test: WHERE is_instant GROUP BY ds ) a - JOIN ( + FULL OUTER JOIN ( SELECT CAST(NULLIF(SUM(booking_value), 0) AS {{ double_data_type_name }} ) AS booking_value , ds @@ -153,7 +153,7 @@ integration_test: WHERE dul_west.home_state_latest IN ('CA', 'HI', 'WA') GROUP BY fa_west_filtered.ds ) a - JOIN ( + FULL OUTER JOIN ( SELECT CAST(SUM(account_balance) AS {{ double_data_type_name }}) AS total_account_balance_first_day , fa_east_filtered.ds diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index d0d5591ab4..425bae5fb1 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -284,7 +284,7 @@ integration_test: GROUP BY ds ) groupby_8cbdaa28 - JOIN ( + FULL OUTER JOIN ( SELECT SUM(1) AS views , ds @@ -350,7 +350,7 @@ integration_test: GROUP BY ds ) groupby_8cbdaa28 - JOIN ( + FULL OUTER JOIN ( SELECT SUM(1) AS listings , created_at AS ds diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml index f25d9f6748..ae67a800bb 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml index 7de1511904..8bdcd7e080 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml index 22856f8489..26a114d041 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index b2a2aec6c3..fc7317598e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/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 @@ -387,7 +387,7 @@ FROM ( , listing__country_latest ) subq_8 ) subq_9 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_18.ds__day @@ -689,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 + ds__day + , listing__country_latest ) subq_20 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index e540931fcd..fb551dce52 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/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 FLOAT64) / CAST(NULLIF(subq_40.views, 0) AS FLOAT64) AS bookings_per_view + ds__day + , listing__country_latest + , CAST(bookings AS FLOAT64) / CAST(NULLIF(views, 0) AS FLOAT64) 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 - DATE_TRUNC(ds, day) 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 - ds__day - , listing__country_latest -) 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(ds, day) 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 + ds__day + , listing__country_latest + ) 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 - DATE_TRUNC(ds, day) 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(ds, day) 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 + ds__day + , listing__country_latest + ) subq_40 ON - subq_33.listing = listings_latest_src_10004.listing_id - GROUP BY - ds__day - , listing__country_latest -) 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 + ds__day + , listing__country_latest +) subq_41 diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index cce4a6d693..b619d75d13 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/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 @@ -387,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 @@ -689,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/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 03f2aa3d7e..b53b1f06f4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/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 - 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 -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 - 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 + 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/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index 6a9d428c0a..e945f2d50c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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 @@ -387,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 @@ -689,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/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 03f2aa3d7e..b53b1f06f4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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 - 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 -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 - 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 + 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/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index 0252714d7d..19b030239b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/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 @@ -387,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 @@ -689,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/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 4baa44160e..9526df6729 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/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 PRECISION) / CAST(NULLIF(subq_40.views, 0) AS DOUBLE PRECISION) AS bookings_per_view + ds__day + , listing__country_latest + , CAST(bookings AS DOUBLE PRECISION) / CAST(NULLIF(views, 0) AS DOUBLE PRECISION) 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 - 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 -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 - 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 + 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/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index a4dafff587..8efb1d7083 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/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 @@ -387,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 @@ -689,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/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 4baa44160e..9526df6729 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/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 PRECISION) / CAST(NULLIF(subq_40.views, 0) AS DOUBLE PRECISION) AS bookings_per_view + ds__day + , listing__country_latest + , CAST(bookings AS DOUBLE PRECISION) / CAST(NULLIF(views, 0) AS DOUBLE PRECISION) 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 - 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 -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 - 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 + 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/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index e581853f54..81aee1e5e8 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/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 @@ -387,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 @@ -689,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/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 03f2aa3d7e..b53b1f06f4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/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 - 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 -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 - 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 + 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/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml index a20f2ab36a..c7c329e83e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml @@ -22,27 +22,35 @@ - + - + - - - - - - - - + + + + + + + + - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql index 3e56dbc93a..2f6627ec7f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_6.metric_time__day = subq_11.metric_time__day + GROUP BY + metric_time__day ) subq_12 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql index c9c233de49..5b744a582e 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 FLOAT64) / CAST(NULLIF(subq_24.booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio + metric_time__day + , CAST(booking_value_with_is_instant_constraint AS FLOAT64) / CAST(NULLIF(booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio FROM ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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(ds, day) 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - DATE_TRUNC(ds, day) AS metric_time__day - , SUM(booking_value) AS booking_value - FROM ***************************.fct_bookings bookings_source_src_10001 + GROUP BY + metric_time__day + ) subq_24 + ON + subq_19.metric_time__day = subq_24.metric_time__day GROUP BY metric_time__day -) 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 - ) - ) +) subq_25 diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 7427967f1c..4a2b12935f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 83d7ab2a40..e66020c868 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Metrics -- Compute Metrics via Expressions SELECT - CAST(subq_15.bookings AS FLOAT64) / CAST(NULLIF(subq_20.listings, 0) AS FLOAT64) AS bookings_per_listing + CAST(MAX(subq_15.bookings) AS FLOAT64) / CAST(NULLIF(MAX(subq_20.listings), 0) AS FLOAT64) AS bookings_per_listing FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql index 805de5201b..4609e7f48e 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_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/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql index 36878b678c..77f5d693df 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 + 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 ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - 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 - ( + GROUP BY + DATE_TRUNC('day', 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 - ) - ) + 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/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index bdf1479a4d..e36b3d9819 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 9be945ab42..8a1096e90f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- 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 + 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' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql index a2fb429ea9..c4e6b9b0d5 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_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/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql index 36878b678c..77f5d693df 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 + 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 ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - 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 - ( + GROUP BY + DATE_TRUNC('day', 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 - ) - ) + 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/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 6169511027..01f9725d4d 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 9be945ab42..8a1096e90f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- 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 + 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' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql index 5493cc3251..d69116c39b 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_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/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql index c466ba6856..dca28f5735 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 PRECISION) / CAST(NULLIF(subq_24.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + metric_time__day + , CAST(booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - 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 - ( + GROUP BY + DATE_TRUNC('day', 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 - ) - ) + 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/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 1c31c9b36b..20f37cdbd8 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 331adf393b..31bce3d483 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Metrics -- Compute Metrics via Expressions SELECT - CAST(subq_15.bookings AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.listings, 0) AS DOUBLE PRECISION) AS bookings_per_listing + CAST(MAX(subq_15.bookings) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_20.listings), 0) AS DOUBLE PRECISION) AS bookings_per_listing FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql index c239e17531..3ffd151578 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_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/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql index c466ba6856..dca28f5735 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 PRECISION) / CAST(NULLIF(subq_24.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + metric_time__day + , CAST(booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - 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 - ( + GROUP BY + DATE_TRUNC('day', 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 - ) - ) + 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/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index b18e57eb14..45490517f3 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 331adf393b..31bce3d483 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Metrics -- Compute Metrics via Expressions SELECT - CAST(subq_15.bookings AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.listings, 0) AS DOUBLE PRECISION) AS bookings_per_listing + CAST(MAX(subq_15.bookings) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_20.listings), 0) AS DOUBLE PRECISION) AS bookings_per_listing FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql index fcef034238..92e948277e 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -240,7 +240,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ) subq_6 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_10.metric_time__day @@ -457,13 +457,7 @@ FROM ( ) 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_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/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql index 36878b678c..77f5d693df 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -1,53 +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 + 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 ( - -- Constrain Output with WHERE - -- Pass Only Elements: - -- ['booking_value', 'metric_time__day'] - -- Aggregate Measures - -- Compute Metrics via Expressions + -- Combine Metrics SELECT - metric_time__day - , SUM(booking_value) AS booking_value_with_is_instant_constraint + 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', 'booking__is_instant', 'metric_time__day'] + -- ['booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions SELECT DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , booking_value + , SUM(booking_value) AS 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 - 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 - ( + GROUP BY + DATE_TRUNC('day', 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 - ) - ) + 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/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 92e274b621..b7e32bf2f2 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -4,8 +4,8 @@ SELECT FROM ( -- Combine Metrics SELECT - subq_4.bookings AS bookings - , subq_9.listings AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 9be945ab42..8a1096e90f 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- 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 + 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' diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml index 59b7d47c75..31896ee893 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml @@ -20,7 +20,8 @@ - + + @@ -126,7 +127,8 @@ - + +