From 10138b02f24d783dd9e09b69f8eb31f92902a5c8 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 10 Oct 2024 08:59:07 -0700 Subject: [PATCH] Remove unneeded group bys from time spine dataset (#1453) We've been applying an unnecessary group by to the time spine dataset. Previously, we were applying group bys whenever a `DATE_TRUNC` column was included in the select statement, _even if_ the base grain was included in the select statement. These group bys are unnecessary, because If there is no `DATE_TRUNC` applied to one select column, then none of the columns will be changed by the group by. For example: ``` SELECT ds , DATE_TRUNC(ds, month) FROM time_spine GROUP BY ds, DATE_TRUNC(ds, month) ``` will return the same result as: ``` SELECT ds , DATE_TRUNC(ds, month) FROM time_spine ``` The results are the same, but the first query is inefficient because of the unnecessary group by. This PR removes the unnecessary group bys. Note that if the base grain is not included, the group by is still necessary. I recommend reviewing by commit because the number of snapshot changes is very large. --- .../unreleased/Fixes-20241009-174346.yaml | 6 ++++ metricflow/plan_conversion/dataflow_to_sql.py | 8 ++--- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 21 ++++---------- ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 19 ++++-------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 19 ++++-------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 19 ++++-------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 17 +++-------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 19 ++++-------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 19 ++++-------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 23 ++++----------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 19 ++++-------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 23 ++++----------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 27 +++++------------ ...c_with_agg_time_and_metric_time__plan0.sql | 3 -- ..._time_and_metric_time__plan0_optimized.sql | 23 +++++---------- ...th_multiple_agg_time_dimensions__plan0.sql | 3 -- ...e_agg_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...multiple_metric_time_dimensions__plan0.sql | 3 -- ...etric_time_dimensions__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 21 ++++---------- ..._metric_with_non_default_grains__plan0.sql | 3 -- ...th_non_default_grains__plan0_optimized.sql | 23 +++++---------- ...e_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- ...w_metric_with_non_default_grain__plan0.sql | 3 -- ...ith_non_default_grain__plan0_optimized.sql | 23 +++++---------- ..._metric_with_non_default_grains__plan0.sql | 4 --- ...th_non_default_grains__plan0_optimized.sql | 29 ++++++------------- 142 files changed, 505 insertions(+), 1402 deletions(-) create mode 100644 .changes/unreleased/Fixes-20241009-174346.yaml diff --git a/.changes/unreleased/Fixes-20241009-174346.yaml b/.changes/unreleased/Fixes-20241009-174346.yaml new file mode 100644 index 0000000000..aab55d27a5 --- /dev/null +++ b/.changes/unreleased/Fixes-20241009-174346.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Remove unnecessary group bys that make queries less efficient. +time: 2024-10-09T17:43:46.011252-07:00 +custom: + Author: courtneyholcomb + Issue: "1453" diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 87be3f85cd..d0c8a97546 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -263,18 +263,18 @@ def _make_time_spine_data_set( table_alias=time_spine_table_alias, column_name=time_spine_source.base_column ) select_columns: Tuple[SqlSelectColumn, ...] = () - apply_group_by = False + apply_group_by = True for agg_time_dimension_instance in agg_time_dimension_instances: column_alias = self.column_association_resolver.resolve_spec(agg_time_dimension_instance.spec).column_name # If the requested granularity is the same as the granularity of the spine, do a direct select. - # TODO: also handle date part. agg_time_grain = agg_time_dimension_instance.spec.time_granularity assert ( not agg_time_grain.is_custom_granularity ), "Custom time granularities are not yet supported for all queries." if agg_time_grain.base_granularity == time_spine_source.base_granularity: select_columns += (SqlSelectColumn(expr=column_expr, column_alias=column_alias),) - # If any columns have a different granularity, apply a DATE_TRUNC() and aggregate via group_by. + apply_group_by = False + # If any columns have a different granularity, apply a DATE_TRUNC(). else: select_columns += ( SqlSelectColumn( @@ -284,7 +284,7 @@ def _make_time_spine_data_set( column_alias=column_alias, ), ) - apply_group_by = True + # TODO: also handle date part. return SqlDataSet( instance_set=time_spine_instance_set, diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0.sql index a2f0fe2a62..316a400d37 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week , DATETIME_TRUNC(subq_3.ds, quarter) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__week - , metric_time__quarter ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index b9a4fa76c0..d73d322978 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,27 +21,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATETIME_TRUNC(subq_12.ds, isoweek) AS metric_time__week + , DATETIME_TRUNC(subq_12.ds, quarter) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, isoweek) AS metric_time__week - , DATETIME_TRUNC(ds, quarter) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - metric_time__day - , metric_time__week - , metric_time__quarter - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.ds ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 83ccdafc37..9a380af47b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATETIME_TRUNC(subq_3.ds, month) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - revenue_instance__ds__month - , metric_time__day ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index 35a428887f..92ecb975a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,26 +3,17 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATETIME_TRUNC(subq_10.ds, month) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATETIME_TRUNC(ds, month) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - revenue_instance__ds__month - , metric_time__day -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_9.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_10.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_10.ds AS DATETIME), INTERVAL 2 month) ) GROUP BY revenue_instance__ds__month diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index c068c9dc98..9a2756e2e4 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATETIME_TRUNC(subq_3.ds, month) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - revenue_instance__ds__day - , revenue_instance__ds__month ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index 890e5a2d78..55c6a28bcb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,26 +3,17 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATETIME_TRUNC(subq_10.ds, month) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATETIME_TRUNC(ds, month) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - revenue_instance__ds__day - , revenue_instance__ds__month -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_9.revenue_instance__ds__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_10.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_9.revenue_instance__ds__day AS DATETIME), INTERVAL 2 month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_10.ds AS DATETIME), INTERVAL 2 month) ) GROUP BY revenue_instance__ds__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index caddda4623..e9ecb3012a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__month ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index bfbdc21801..9fc90bbefa 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,26 +3,17 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATETIME_TRUNC(subq_10.ds, month) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - metric_time__day - , metric_time__month -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_9.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_10.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_10.ds AS DATETIME), INTERVAL 2 month) ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0.sql index d3e05331c4..5a32c02251 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__week ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 33aac00a24..fdb226eeab 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,24 +17,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATETIME_TRUNC(subq_12.ds, isoweek) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, isoweek) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - metric_time__day - , metric_time__week - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.ds ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index a216c5d3ef..04d2e6bc32 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__week ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 8ceaaa47ac..03bf1b955d 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,26 +18,17 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATETIME_TRUNC(subq_13.ds, isoweek) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, isoweek) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - metric_time__day - , metric_time__week - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_13.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 2 month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 2 month) ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0.sql index 63d46c0285..8b8fffd466 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__month ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 93e1a59663..9d34e5ebc5 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,26 +17,17 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATETIME_TRUNC(subq_12.ds, month) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - metric_time__day - , metric_time__month - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) >= DATETIME_TRUNC(subq_11.metric_time__day, month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) >= DATETIME_TRUNC(subq_12.ds, month) ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 51ffc30cdd..a27dd03f80 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATETIME_TRUNC(subq_3.ds, year) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - revenue_instance__ds__quarter - , revenue_instance__ds__year - , metric_time__day ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 0c9bfbbc88..cc67ceda02 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,29 +21,18 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATETIME_TRUNC(subq_12.ds, quarter) AS revenue_instance__ds__quarter + , DATETIME_TRUNC(subq_12.ds, year) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATETIME_TRUNC(ds, quarter) AS revenue_instance__ds__quarter - , DATETIME_TRUNC(ds, year) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - revenue_instance__ds__quarter - , revenue_instance__ds__year - , metric_time__day - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) >= DATETIME_TRUNC(subq_11.metric_time__day, month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) >= DATETIME_TRUNC(subq_12.ds, month) ) GROUP BY revenue_instance__ds__quarter diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0.sql index b0558dd480..643c8d2d08 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, year) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - metric_time__day - , metric_time__year ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0_optimized.sql index c1bbe03265..52691bc6c0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,26 +13,17 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATETIME_TRUNC(subq_12.ds, year) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATETIME_TRUNC(ds, year) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - metric_time__day - , metric_time__year - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day + DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_12.ds ) AND ( - DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_11.metric_time__day AS DATETIME), INTERVAL 2 month) + DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_12.ds AS DATETIME), INTERVAL 2 month) ) GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql index 3359122720..d2e200202c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - booking__ds__month - , metric_time__day - , metric_time__week ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql index 165b5a6198..af0a033349 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,29 +29,18 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATETIME_TRUNC(subq_15.ds, month) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATETIME_TRUNC(subq_15.ds, isoweek) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATETIME_TRUNC(ds, month) AS booking__ds__month - , ds AS metric_time__day - , DATETIME_TRUNC(ds, isoweek) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - booking__ds__month - , metric_time__day - , metric_time__week - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_14.metric_time__day + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_14.metric_time__day AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) ) GROUP BY booking__ds__month diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0.sql index 0638629bfb..095212d4a4 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 22de7b52c0..9599401b43 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index af273a6d27..7d5604b836 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index abb3344a26..b1734b6697 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index 6caf616294..286f530a98 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.revenue_instance__ds__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index 48ebb94d10..ecfa72595a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 793cd64067..c81dadb7e8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0.sql index 183461ce6a..f510f3df6a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index f3f9badc38..7a08f08ae3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 94d66c8da0..64ef96c161 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds) ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0.sql index 15f75c76cd..90e3176a58 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 5318ca0d14..306bf4946a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0.sql index 1b608ce209..563fa96f91 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0_optimized.sql index f2214f335f..af16e9d076 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql index 71573a57be..9e0e39273c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql index 40268062b2..0de21ac7b8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.metric_time__day) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql index 417d11e301..e18d6d8867 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 78a6550fbd..a0296e5753 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index eaaba26ba2..55074544ae 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - INTERVAL 2 month ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 08079e14cc..4439195d94 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index df79dc0757..33993634a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.revenue_instance__ds__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - INTERVAL 2 month ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index ec77b12959..27fb0b9e4e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 5a4fb59200..6026bfbbbe 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - INTERVAL 2 month ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql index a83909ad88..1de175b2a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index 95969c9da1..4bacd09f19 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 363d16e9bd..6f4d9e39fb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_13.ds - INTERVAL 2 month ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql index aab94914af..5c0cc6861f 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 92e8a38290..d2e514d119 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql index cf6722d1ca..3436052379 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql index 03e4ba7fc4..59c39cfceb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_11.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.ds - INTERVAL 2 month ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql index 113268bbb1..f02a95f7fc 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql index d2e2b91c1d..61f2654313 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.metric_time__day - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0.sql index 417d11e301..e18d6d8867 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 203f1ddd3d..10b9060b34 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index f00cf20a1b..cfba41e2c1 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - MAKE_INTERVAL(months => 2) + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - MAKE_INTERVAL(months => 2) ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 443cc1255e..f39d0687dc 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index fb051bf687..4a99efc660 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.revenue_instance__ds__day - MAKE_INTERVAL(months => 2) + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - MAKE_INTERVAL(months => 2) ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index aafb23085c..241af07cff 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 95a3491e9a..e4903de984 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - MAKE_INTERVAL(months => 2) + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - MAKE_INTERVAL(months => 2) ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0.sql index a83909ad88..1de175b2a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index d370d57659..e3b7882afe 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index c1d8a4cf36..399230aea6 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.metric_time__day - MAKE_INTERVAL(months => 2) + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_13.ds - MAKE_INTERVAL(months => 2) ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0.sql index aab94914af..5c0cc6861f 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 92e8a38290..d2e514d119 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0.sql index 1a209eb763..e67054deee 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0_optimized.sql index 960caea152..d1687a1592 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_11.metric_time__day - MAKE_INTERVAL(months => 2) + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.ds - MAKE_INTERVAL(months => 2) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql index 6013cb41c7..d10a11c213 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql index c16233e6e5..9caba7b61e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.metric_time__day - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - MAKE_INTERVAL(days => 2) ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0.sql index 29429e102b..8cd8bf0b6a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index b6b4ae0325..2cdb297db6 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index af273a6d27..7d5604b836 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 7bd3132dc3..99aa8df844 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index 6caf616294..286f530a98 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.revenue_instance__ds__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index 1d665cb206..8902359444 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 793cd64067..c81dadb7e8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0.sql index 803fc0e985..fcb0ecf1eb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index 909304264a..399b6d8bc6 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 94d66c8da0..64ef96c161 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds) ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0.sql index 1d1319c7ef..431f05d88c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0.sql index ae51abd0a2..3ba46e1c92 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0.sql index c49c049b91..bcc30b8c54 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0_optimized.sql index f2214f335f..af16e9d076 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql index 81608c0b83..4023666160 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql index 40268062b2..0de21ac7b8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.metric_time__day) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0.sql index 1c9a57d92b..4a3da9081b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 291d204d49..df5c02ee19 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index af273a6d27..7d5604b836 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index bbb80a8f2c..502dd06109 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index 6caf616294..286f530a98 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.revenue_instance__ds__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index 9ea017acab..1ccb132272 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 793cd64067..c81dadb7e8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_10.ds) ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0.sql index 1e140d9bee..c73dbfd71f 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index fe91f8515e..52cd998690 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 94d66c8da0..64ef96c161 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds) ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0.sql index 421acf6ca5..a09f53583d 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 06484eb416..1ef3533096 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0.sql index 5ff4e09f97..1b541aa7f7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0_optimized.sql index f2214f335f..af16e9d076 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql index 54f9b7a5f9..cada9c1b77 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql index 40268062b2..0de21ac7b8 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.metric_time__day) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0.sql index 8a5ddb3468..d460000bb4 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..5150db08e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,32 +21,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_12.ds) AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - , DATE_TRUNC('quarter', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) + , DATE_TRUNC('quarter', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 273e14d03f..a0fe897b26 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -60,9 +60,6 @@ FROM ( DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index 251cdb4cb8..b9c7a738fe 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month + , subq_10.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - GROUP BY - DATE_TRUNC('month', ds) - , ds -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) + , subq_10.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 6c3054ee99..0eb84051a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index 6072af4f6d..68a852e450 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_10.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_10.ds) AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS revenue_instance__ds__day - , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_9.revenue_instance__ds__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_10.ds) ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index 4ab76dcbe5..52db65a0af 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -60,9 +60,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index a2359e82ea..26a51cc775 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,18 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 - GROUP BY - ds - , DATE_TRUNC('month', ds) -) subq_9 +FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_9.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_10.ds) ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0.sql index 050b90fe7a..e35cb4930b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4f9ccb637e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,28 +17,19 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_12.ds AS metric_time__day + , DATE_TRUNC('week', subq_12.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week + subq_12.ds + , DATE_TRUNC('week', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index 7a89445ace..33a9a748d5 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -75,9 +75,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index f052f1929e..6505377193 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,30 +18,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_13.ds AS metric_time__day + , DATE_TRUNC('week', subq_13.ds) AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 - GROUP BY - ds - , DATE_TRUNC('week', ds) - ) subq_12 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_12.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_13.ds) ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week + subq_13.ds + , DATE_TRUNC('week', subq_13.ds) ) subq_16 ) subq_18 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0.sql index d94209433b..af32d922f6 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -74,9 +74,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..774caad966 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,21 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_12.ds AS metric_time__day + , DATE_TRUNC('month', subq_12.ds) AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('month', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month + subq_12.ds + , DATE_TRUNC('month', subq_12.ds) ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0.sql index c980cdc75d..0ff02ff3bd 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -82,10 +82,6 @@ FROM ( , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year , subq_3.ds AS metric_time__day FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..6ab8a6d40c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,34 +21,23 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + DATE_TRUNC('quarter', subq_12.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_12.ds) AS revenue_instance__ds__year + , subq_12.ds AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - GROUP BY - DATE_TRUNC('quarter', ds) - , DATE_TRUNC('year', ds) - , ds - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_12.ds) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day + DATE_TRUNC('quarter', subq_12.ds) + , DATE_TRUNC('year', subq_12.ds) + , subq_12.ds ) subq_16 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0.sql index 06f1486ac1..4761087980 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0.sql @@ -70,9 +70,6 @@ FROM ( subq_3.ds AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0_optimized.sql index 5d3f4efe05..d45985174c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,30 +13,21 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_12.ds AS metric_time__day + , DATE_TRUNC('year', subq_12.ds) AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue - FROM ( - -- Time Spine - SELECT - ds AS metric_time__day - , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 - GROUP BY - ds - , DATE_TRUNC('year', ds) - ) subq_11 + FROM ***************************.mf_time_spine subq_12 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) > DATE_ADD('month', -2, subq_12.ds) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year + subq_12.ds + , DATE_TRUNC('year', subq_12.ds) ) subq_15 ) subq_17 GROUP BY diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql index 807067cba5..db86eeb24e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql @@ -157,10 +157,6 @@ FROM ( , subq_3.ds AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql index 7ed947b747..6beb477bc0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -29,34 +29,23 @@ FROM ( -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + DATE_TRUNC('month', subq_15.ds) AS booking__ds__month + , subq_15.ds AS metric_time__day + , DATE_TRUNC('week', subq_15.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day - , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 - GROUP BY - DATE_TRUNC('month', ds) - , ds - , DATE_TRUNC('week', ds) - ) subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_14.metric_time__day) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_15.ds) ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week + DATE_TRUNC('month', subq_15.ds) + , subq_15.ds + , DATE_TRUNC('week', subq_15.ds) ) subq_18 ON subq_20.ds = subq_18.metric_time__day