diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 77aaf112cf..650408bbe8 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -241,14 +241,14 @@ 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=SqlJoinType.FULL_OUTER if MetricType.DERIVED else SqlJoinType.INNER, + combine_metrics_join_type=join_type, ), metric_specs=[metric_spec], ) diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index ff3a87a121..1ae004a3bb 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -42,7 +42,7 @@ integration_test: FROM {{source_schema}}.fct_bookings GROUP BY ds ) b - JOIN ( + FULL OUTER JOIN ( SELECT SUM(1) AS views , ds @@ -519,7 +519,7 @@ integration_test: GROUP BY ds ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT SUM(1) AS lux_listings , created_at AS metric_time__day @@ -654,7 +654,7 @@ integration_test: ON a.listing_id = b.listing_id GROUP BY 2 ) bk - INNER JOIN ( + FULL OUTER JOIN ( SELECT SUM(1) AS views ,d.is_lux @@ -683,7 +683,7 @@ integration_test: GROUP BY metric_time__day ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT c.ds AS metric_time__day , d.bookings_2_weeks_ago AS bookings_2_weeks_ago @@ -718,7 +718,7 @@ integration_test: GROUP BY metric_time__day ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT c.ds AS metric_time__day , d.bookings_at_start_of_month AS bookings_at_start_of_month @@ -760,7 +760,7 @@ integration_test: ) f ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT c.ds AS metric_time__day , d.bookings AS month_start_bookings @@ -808,7 +808,7 @@ integration_test: check_query: | SELECT booking_value - instant_booking_value AS booking_value_sub_instant - , a.metric_time__day + , COALESCE(a.metric_time__day, b.metric_time__day) AS metric_time__day FROM ( SELECT SUM(booking_value) AS instant_booking_value @@ -818,7 +818,7 @@ integration_test: GROUP BY ds ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT SUM(booking_value) AS booking_value , ds AS metric_time__day @@ -843,7 +843,7 @@ integration_test: FROM ( SELECT booking_value - instant_booking_value AS booking_value_sub_instant - , a.metric_time__day AS metric_time__day + , COALESCE(a.metric_time__day, b.metric_time__day) AS metric_time__day FROM ( SELECT SUM(booking_value) AS instant_booking_value @@ -853,7 +853,7 @@ integration_test: GROUP BY ds ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT SUM(booking_value) AS booking_value , ds AS metric_time__day @@ -901,7 +901,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings GROUP BY metric_time__week ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} AS metric_time__week , SUM(d.bookings_at_start_of_month) AS bookings_at_start_of_month @@ -944,7 +944,7 @@ integration_test: ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day GROUP BY metric_time__year ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT {{ render_date_trunc("c.ds", TimeGranularity.YEAR) }} AS metric_time__year , SUM(d.bookings) AS month_start_bookings @@ -1024,7 +1024,7 @@ integration_test: FROM {{ source_schema }}.fct_bookings GROUP BY metric_time__week, metric_time__month ) a - INNER JOIN ( + FULL OUTER JOIN ( SELECT {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} AS metric_time__week , {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} AS metric_time__month @@ -1290,7 +1290,7 @@ integration_test: ) subq_3 ON subq_5.ds = subq_3.metric_time__day ) subq_7 - INNER JOIN ( + FULL OUTER JOIN ( SELECT subq_11.ds AS metric_time__day , SUM(subq_9.bookings) AS bookings_2_weeks_ago 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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql index 127ebba768..85eee899d7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql index ace6863100..f7d37d45b3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 9ee6e81037..d8bb186c28 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index a952516e96..6d1b17b416 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index b526384e42..9e51107f26 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index e5a7e1789c..5b18fcfa5f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index 4c269caac4..ff86172aba 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql index 612203ca28..85492077fe 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 1eca8bda82..b63165d712 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index db8895099d..babc99022a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 23be1ba20e..81ba9df25d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql index d7ab098327..0e23b840ec 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql index 519c4b6ea5..86124d9091 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.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_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 903c3820ae..82f482abd5 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.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_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index a04d6e7a77..09cde7d286 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.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_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index a03cec3919..8e374bcc1b 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.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_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql index 31f8ab6fcc..d808676df4 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.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_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_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 @@ - + +