diff --git a/.changes/unreleased/Breaking Changes-20231102-182815.yaml b/.changes/unreleased/Breaking Changes-20231102-182815.yaml new file mode 100644 index 0000000000..a0963ecce2 --- /dev/null +++ b/.changes/unreleased/Breaking Changes-20231102-182815.yaml @@ -0,0 +1,6 @@ +kind: Breaking Changes +body: Use FULL OUTER JOIN to combine input metrics for derived metrics. This is a change from using INNER JOIN and may result in changes in output. +time: 2023-11-02T18:28:15.181064-07:00 +custom: + Author: courtneyholcomb + Issue: "841" diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 32634cb0c5..7a63e5488e 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -248,7 +248,7 @@ def _build_metrics_output_node( queried_linkable_specs=queried_linkable_specs, where_constraint=where_constraint, time_range_constraint=time_range_constraint, - combine_metrics_join_type=SqlJoinType.INNER, + combine_metrics_join_type=SqlJoinType.FULL_OUTER, ), metric_specs=[metric_spec], ) diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml index 5c641dbf52..acfd39d3dd 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml index 4f7b4fba1e..374e7da04d 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml index 14e3100122..0e45438be4 100644 --- a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml @@ -15,7 +15,8 @@ - + + 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/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/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 903c3820ae..82f482abd5 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -6,8 +6,8 @@ FROM ( -- Combine Metrics SELECT COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , subq_7.bookings_fill_nulls_with_0 AS bookings_fill_nulls_with_0 - , subq_15.bookings_2_weeks_ago AS bookings_2_weeks_ago + , MAX(subq_7.bookings_fill_nulls_with_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 @@ -238,7 +238,7 @@ FROM ( subq_4.metric_time__day = subq_3.metric_time__day ) subq_6 ) subq_7 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_14.metric_time__day @@ -555,13 +555,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index a04d6e7a77..09cde7d286 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -6,8 +6,8 @@ FROM ( -- Combine Metrics SELECT COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , subq_24.bookings_fill_nulls_with_0 AS bookings_fill_nulls_with_0 - , subq_32.bookings_2_weeks_ago AS bookings_2_weeks_ago + , MAX(subq_24.bookings_fill_nulls_with_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 @@ -41,7 +41,7 @@ FROM ( subq_22.ds = subq_20.metric_time__day ) subq_23 ) subq_24 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__day'] @@ -65,13 +65,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql index 127ebba768..85eee899d7 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql @@ -6,8 +6,8 @@ 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 + , MAX(subq_4.ref_bookings) AS ref_bookings + , MAX(subq_9.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__day ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_8.metric_time__day @@ -441,13 +441,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql index ace6863100..f7d37d45b3 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , MAX(subq_15.ref_bookings) AS ref_bookings + , MAX(subq_20.bookings) AS bookings FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__day ) subq_15 - INNER JOIN ( + FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT @@ -47,13 +47,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 9ee6e81037..d8bb186c28 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__day ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_11.metric_time__day @@ -541,13 +541,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index a952516e96..6d1b17b416 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__day ) subq_18 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__day'] @@ -51,13 +51,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index b526384e42..9e51107f26 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__week ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_11.metric_time__week @@ -542,13 +542,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index e5a7e1789c..5b18fcfa5f 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__week ) subq_18 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__week'] @@ -52,13 +52,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index 4c269caac4..ff86172aba 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -6,8 +6,8 @@ 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 + , MAX(subq_4.bookings) AS bookings + , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__day ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_11.metric_time__day @@ -541,13 +541,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql index 612203ca28..85492077fe 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__day ) subq_18 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__day'] @@ -51,13 +51,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 1eca8bda82..b63165d712 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -6,8 +6,8 @@ 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 + , MAX(subq_4.bookings) AS bookings + , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__quarter ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_11.metric_time__quarter @@ -541,13 +541,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index db8895099d..babc99022a 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__quarter ) subq_18 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__quarter'] @@ -51,13 +51,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 23be1ba20e..81ba9df25d 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -324,7 +324,7 @@ FROM ( subq_5.metric_time__day ) subq_6 ) subq_7 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_14.metric_time__day @@ -641,13 +641,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index a01918dbd2..9127806db2 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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: @@ -31,7 +31,7 @@ FROM ( GROUP BY subq_20.ds ) subq_24 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__day'] @@ -55,13 +55,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index c6f5d6fd56..345740c7ad 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -325,7 +325,7 @@ FROM ( subq_5.metric_time__year ) subq_6 ) subq_7 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_14.metric_time__year @@ -642,13 +642,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 570c54fab1..e0166fe3f3 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/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/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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: @@ -32,7 +32,7 @@ FROM ( GROUP BY DATE_TRUNC('year', subq_20.ds) ) subq_24 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__year'] @@ -56,13 +56,7 @@ FROM ( 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql index d7ab098327..0e23b840ec 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql @@ -6,9 +6,9 @@ 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 + , 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 @@ -18,8 +18,8 @@ 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 + , MAX(subq_4.ref_bookings) AS ref_bookings + , MAX(subq_9.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT @@ -236,7 +236,7 @@ FROM ( subq_2.metric_time__day ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_8.metric_time__day @@ -453,18 +453,12 @@ FROM ( ) 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_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 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_15.metric_time__day @@ -681,16 +675,8 @@ FROM ( ) 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 ( + subq_11.metric_time__day = subq_16.metric_time__day + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_20.metric_time__day @@ -907,13 +893,7 @@ FROM ( ) 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 - ) - ) + 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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql index 519c4b6ea5..86124d9091 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql @@ -6,9 +6,9 @@ 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 + , 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 @@ -18,8 +18,8 @@ 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 + , MAX(subq_27.ref_bookings) AS ref_bookings + , MAX(subq_32.bookings) AS bookings FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -39,7 +39,7 @@ FROM ( GROUP BY metric_time__day ) subq_27 - INNER JOIN ( + FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT @@ -59,18 +59,12 @@ FROM ( 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_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 - INNER JOIN ( + FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT @@ -90,16 +84,8 @@ FROM ( 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 ( + subq_34.metric_time__day = subq_39.metric_time__day + FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT @@ -119,13 +105,7 @@ FROM ( 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 - ) - ) + 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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index a03cec3919..8e374bcc1b 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -6,8 +6,8 @@ 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 + , MAX(subq_4.bookings) AS bookings + , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -224,7 +224,7 @@ FROM ( subq_2.metric_time__extract_dow ) subq_3 ) subq_4 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_11.metric_time__extract_dow @@ -541,13 +541,7 @@ FROM ( ) 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_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_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql index 31f8ab6fcc..d808676df4 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql @@ -6,8 +6,8 @@ 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 + , 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 @@ -27,7 +27,7 @@ FROM ( GROUP BY metric_time__extract_dow ) subq_18 - INNER JOIN ( + FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: -- ['bookings', 'metric_time__extract_dow'] @@ -51,13 +51,7 @@ FROM ( EXTRACT(isodow 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_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_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 bd7bff1c0a..a9ce8605a0 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 @@ -21,27 +21,35 @@ - + - + - - - - - - - - + + + + + + + + - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_fill_nulls_for_one_input_metric__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_fill_nulls_for_one_input_metric__plan0.xml index 38db655e64..0dea3d045c 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_fill_nulls_for_one_input_metric__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_fill_nulls_for_one_input_metric__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric__plan0.xml index e9a60a425b..e5774f9379 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain__plan0.xml index fe0b52659f..c73c582ba9 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain_and_granularity__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain_and_granularity__plan0.xml index f66b82261c..cd99948a94 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain_and_granularity__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_to_grain_and_granularity__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window__plan0.xml index 5a2df47005..a0231551ad 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_granularity__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_granularity__plan0.xml index d44ef8f9cb..07e906d15a 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_granularity__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_granularity__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.xml index c3b6719455..a60e8fb37e 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.xml index 5ac2cd2626..87bbf4e0b5 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_nested_derived_metric__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_nested_derived_metric__plan0.xml index 11a3334069..2701dc9d63 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_nested_derived_metric__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_nested_derived_metric__plan0.xml @@ -4,7 +4,7 @@ - + @@ -15,35 +15,39 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -63,23 +67,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + @@ -1723,7 +1731,7 @@ - + @@ -2532,7 +2540,7 @@ - + diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_offset_window_with_date_part__plan0.xml b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_offset_window_with_date_part__plan0.xml index 92630d354a..c3dfaa0177 100644 --- a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_offset_window_with_date_part__plan0.xml +++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_offset_window_with_date_part__plan0.xml @@ -17,23 +17,27 @@ - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql index dbb29c4d73..ba7e10edd2 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql @@ -6,9 +6,9 @@ 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 + , 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 @@ -398,7 +398,7 @@ FROM ( subq_9.metric_time__day ) subq_10 ) subq_11 - INNER JOIN ( + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_22.metric_time__day @@ -788,16 +788,8 @@ FROM ( ) 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 ( + subq_11.metric_time__day = subq_23.metric_time__day + FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT subq_27.metric_time__day @@ -1014,13 +1006,7 @@ FROM ( ) 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 - ) - ) + 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/DuckDB/test_measure_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql index bf23abb3af..0b555b1430 100644 --- a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql @@ -6,9 +6,9 @@ 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 + , 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: @@ -36,7 +36,7 @@ FROM ( GROUP BY metric_time__day ) subq_41 - INNER JOIN ( + FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: -- ['bookings', 'metric_time__day'] @@ -74,16 +74,8 @@ FROM ( 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 ( + 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: @@ -98,13 +90,7 @@ FROM ( DATE_TRUNC('day', 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 - ) - ) + 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/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_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 @@ - + + diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml index 4d72662222..e10bd4a7a0 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml @@ -15,7 +15,8 @@ - + + diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml index a26d3cb22b..e1d61a2ec1 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml @@ -65,7 +65,8 @@ - + + diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml index 5af98e9f24..949bae2ee7 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml @@ -15,7 +15,8 @@ - + + @@ -29,7 +30,8 @@ - + + diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml index dcccd29791..a4137fb8ab 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml @@ -15,7 +15,8 @@ - + +