From d6e927d34f9d140bdafbabe7edbb1f4155e4153b Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 18 Jun 2024 16:20:19 -0700 Subject: [PATCH 01/13] Changelog --- .changes/unreleased/Under the Hood-20240618-161241.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20240618-161241.yaml diff --git a/.changes/unreleased/Under the Hood-20240618-161241.yaml b/.changes/unreleased/Under the Hood-20240618-161241.yaml new file mode 100644 index 0000000000..d5078f005b --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240618-161241.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Consume cumulative-specific metric type params from new cumulative_type_params + field. +time: 2024-06-18T16:12:41.132445-07:00 +custom: + Author: courtneyholcomb + Issue: "1293" From 950d62ee4993b75e497107a6cd4b3476e3c809a1 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 18 Jun 2024 16:21:50 -0700 Subject: [PATCH 02/13] Apply SetCumulativeTypeParamsRule transformation This will ensure that any window or grain_to_date set in the type_params fields will be copied into the corresponding cumulative_type_params fields. --- .../metricflow_semantics/model/dbt_manifest_parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py b/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py index ea1ba90c9c..0e3d9a32fa 100644 --- a/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py +++ b/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py @@ -10,6 +10,7 @@ from dbt_semantic_interfaces.transformations.convert_median import ( ConvertMedianToPercentileRule, ) +from dbt_semantic_interfaces.transformations.cumulative_type_params import SetCumulativeTypeParamsRule from dbt_semantic_interfaces.transformations.names import LowerCaseNamesRule from dbt_semantic_interfaces.transformations.proxy_measure import CreateProxyMeasureRule from dbt_semantic_interfaces.transformations.semantic_manifest_transformer import ( @@ -35,6 +36,7 @@ def parse_manifest_from_dbt_generated_manifest(manifest_json_string: str) -> Pyd ConvertCountToSumRule(), ConvertMedianToPercentileRule(), DedupeMetricInputMeasuresRule(), # Remove once fix is in core + SetCumulativeTypeParamsRule(), ), ) model = PydanticSemanticManifestTransformer.transform(raw_model, rules) From 618d93b0b5472ed02253660368c8c263fec21b24 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 18 Jun 2024 17:29:47 -0700 Subject: [PATCH 03/13] Upgrade DSI --- extra-hatch-configuration/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra-hatch-configuration/requirements.txt b/extra-hatch-configuration/requirements.txt index d48a78461f..2e667590ee 100644 --- a/extra-hatch-configuration/requirements.txt +++ b/extra-hatch-configuration/requirements.txt @@ -1,5 +1,5 @@ Jinja2>=3.1.3 -dbt-semantic-interfaces==0.6.0.dev2 +dbt-semantic-interfaces==0.6.1.dev0 more-itertools>=8.10.0, <10.2.0 pydantic>=1.10.0, <1.11.0 tabulate>=0.8.9 From 415fbeaeff5d50b89074b6f4d51a3cf844876ca3 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 18 Jun 2024 17:30:30 -0700 Subject: [PATCH 04/13] Consume only from new cumulative_type_params fields --- .../model/semantics/linkable_spec_resolver.py | 13 +++++++++---- .../validation_rules/metric_time_requirements.py | 6 +++++- .../query/test_query_parser.py | 3 ++- .../dataflow/builder/dataflow_plan_builder.py | 12 ++++++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py index 77d0fbcd9f..e3584248c2 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py @@ -246,7 +246,10 @@ def _metric_requires_metric_time(self, metric: Metric) -> bool: metrics_to_check = [metric] while metrics_to_check: metric_to_check = metrics_to_check.pop() - if metric_to_check.type_params.window is not None or metric_to_check.type_params.grain_to_date is not None: + if metric_to_check.type_params.cumulative_type_params and ( + metric_to_check.type_params.cumulative_type_params.window is not None + or metric_to_check.type_params.cumulative_type_params.grain_to_date is not None + ): return True for input_metric in metric_to_check.input_metrics: if input_metric.offset_window is not None or input_metric.offset_to_grain is not None: @@ -497,9 +500,11 @@ def _get_metric_time_elements(self, measure_reference: Optional[MeasureReference dimension_type=DimensionType.TIME, entity_links=(), join_path=SemanticModelJoinPath( - left_semantic_model_reference=measure_semantic_model.reference - if measure_semantic_model - else SemanticModelDerivation.VIRTUAL_SEMANTIC_MODEL_REFERENCE, + left_semantic_model_reference=( + measure_semantic_model.reference + if measure_semantic_model + else SemanticModelDerivation.VIRTUAL_SEMANTIC_MODEL_REFERENCE + ), ), # Anything that's not at the base time granularity of the measure's aggregation time dimension # should be considered derived. diff --git a/metricflow-semantics/metricflow_semantics/query/validation_rules/metric_time_requirements.py b/metricflow-semantics/metricflow_semantics/query/validation_rules/metric_time_requirements.py index 794fa2c769..4d8ac2d8f1 100644 --- a/metricflow-semantics/metricflow_semantics/query/validation_rules/metric_time_requirements.py +++ b/metricflow-semantics/metricflow_semantics/query/validation_rules/metric_time_requirements.py @@ -79,7 +79,11 @@ def validate_metric_in_resolution_dag( elif metric.type is MetricType.CUMULATIVE: if ( metric.type_params is not None - and (metric.type_params.window is not None or metric.type_params.grain_to_date is not None) + and metric.type_params.cumulative_type_params is not None + and ( + metric.type_params.cumulative_type_params.window is not None + or metric.type_params.cumulative_type_params.grain_to_date is not None + ) and not query_includes_metric_time_or_agg_time_dimension ): return MetricFlowQueryResolutionIssueSet.from_issue( diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py b/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py index 8a7990c8f7..79f1e57e34 100644 --- a/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py @@ -130,7 +130,8 @@ type: cumulative type_params: measure: revenue - window: 7 days + cumulative_type_params: + window: 7 days --- metric: name: revenue_sub_10 diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index ef1913c06f..4cf1afe3a5 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -495,8 +495,16 @@ def _build_base_metric_output_node( child_metric_offset_to_grain=metric_spec.offset_to_grain, cumulative_description=( CumulativeMeasureDescription( - cumulative_window=metric.type_params.window, - cumulative_grain_to_date=metric.type_params.grain_to_date, + cumulative_window=( + metric.type_params.cumulative_type_params.window + if metric.type_params.cumulative_type_params + else None + ), + cumulative_grain_to_date=( + metric.type_params.cumulative_type_params.grain_to_date + if metric.type_params.cumulative_type_params + else None + ), ) if metric.type is MetricType.CUMULATIVE else None From 440dfba3b946e53887e8acbd31e6edacfc224877 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 18 Jun 2024 17:51:55 -0700 Subject: [PATCH 05/13] Pin metricflow-semantics to latest dev release of DSI - temporarily --- metricflow-semantics/extra-hatch-configuration/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricflow-semantics/extra-hatch-configuration/requirements.txt b/metricflow-semantics/extra-hatch-configuration/requirements.txt index 06d2516101..873d9aca26 100644 --- a/metricflow-semantics/extra-hatch-configuration/requirements.txt +++ b/metricflow-semantics/extra-hatch-configuration/requirements.txt @@ -1,5 +1,5 @@ # dbt Cloud depends on metricflow-semantics (dependency set in dbt-mantle), so DSI must always point to a production version here. -dbt-semantic-interfaces>=0.5.0, <2.0.0 +dbt-semantic-interfaces==0.6.1.dev0 # Temp: pin to dev release to support cumulative_type_params in MF before they get released in prod. graphviz>=0.18.2, <0.21 python-dateutil>=2.9.0, <2.10.0 rapidfuzz>=3.0, <4.0 From 233e7ffd914379881d2583bc8fc598833bafcf92 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 12:46:28 -0700 Subject: [PATCH 06/13] Bump to DSI 0.6.1 --- extra-hatch-configuration/requirements.txt | 2 +- metricflow-semantics/extra-hatch-configuration/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra-hatch-configuration/requirements.txt b/extra-hatch-configuration/requirements.txt index 2e667590ee..79ccb38cb5 100644 --- a/extra-hatch-configuration/requirements.txt +++ b/extra-hatch-configuration/requirements.txt @@ -1,5 +1,5 @@ Jinja2>=3.1.3 -dbt-semantic-interfaces==0.6.1.dev0 +dbt-semantic-interfaces==0.6.1 more-itertools>=8.10.0, <10.2.0 pydantic>=1.10.0, <1.11.0 tabulate>=0.8.9 diff --git a/metricflow-semantics/extra-hatch-configuration/requirements.txt b/metricflow-semantics/extra-hatch-configuration/requirements.txt index 873d9aca26..f574492e7b 100644 --- a/metricflow-semantics/extra-hatch-configuration/requirements.txt +++ b/metricflow-semantics/extra-hatch-configuration/requirements.txt @@ -1,5 +1,5 @@ # dbt Cloud depends on metricflow-semantics (dependency set in dbt-mantle), so DSI must always point to a production version here. -dbt-semantic-interfaces==0.6.1.dev0 # Temp: pin to dev release to support cumulative_type_params in MF before they get released in prod. +dbt-semantic-interfaces>=0.6.1, <2.0.0 # Temp: pin to dev release to support cumulative_type_params in MF before they get released in prod. graphviz>=0.18.2, <0.21 python-dateutil>=2.9.0, <2.10.0 rapidfuzz>=3.0, <4.0 From e75b7077859f7f431c030a5bc66f194a67d1b7bd Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 12:48:35 -0700 Subject: [PATCH 07/13] Add TODO --- .../metricflow_semantics/model/dbt_manifest_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py b/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py index 0e3d9a32fa..638da5283f 100644 --- a/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py +++ b/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py @@ -26,6 +26,7 @@ def parse_manifest_from_dbt_generated_manifest(manifest_json_string: str) -> Pyd # The serialized object in the dbt project does not have all transformations applied to it at # this time, which causes failures with input measure resolution. # TODO: remove this transform call once the upstream changes are integrated into our dependency tree + # TODO: align rules between DSI, here, and MFS (if possible!) rules = ( # Primary (LowerCaseNamesRule(),), From ee1b43c120d051c89b50d8053068c2c658694d9f Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 12:52:13 -0700 Subject: [PATCH 08/13] Update most cumulative metric configs to use cumulative_type_params Left some with the old structure to ensure the transformation is working as expected. --- .../ambiguous_resolution_manifest/metrics.yaml | 3 ++- .../metrics/bookings_cumulative.yaml | 3 ++- .../metrics/bookings_monthly_cumulative.yaml | 3 ++- .../semantic_manifest_yamls/simple_manifest/metrics.yaml | 9 ++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml index edf5f4f722..706d9558c9 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml @@ -70,7 +70,8 @@ metric: type: cumulative type_params: measure: monthly_measure_0 - window: 2 months + cumulative_type_params: + window: 2 months --- metric: name: derived_metric_with_common_filtered_metric_0 diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_cumulative.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_cumulative.yaml index 7b8d1d618b..826e5faaca 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_cumulative.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_cumulative.yaml @@ -4,4 +4,5 @@ metric: type: cumulative type_params: measure: bookings - window: 7 days + cumulative_type_params: + window: 7 days diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_monthly_cumulative.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_monthly_cumulative.yaml index 43463b8dc8..2be97da2df 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_monthly_cumulative.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_monthly_cumulative.yaml @@ -4,4 +4,5 @@ metric: type: cumulative type_params: measure: bookings_monthly - window: 3 month + cumulative_type_params: + window: 3 month diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml index 121f50ab1b..4f65f5516b 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml @@ -135,7 +135,8 @@ metric: type: cumulative type_params: measure: txn_revenue - window: 2 month + cumulative_type_params: + window: 2 month --- metric: name: "revenue_all_time" @@ -158,7 +159,8 @@ metric: type: cumulative type_params: measure: txn_revenue - grain_to_date: month + cumulative_type_params: + grain_to_date: month --- metric: name: booking_fees @@ -629,7 +631,8 @@ metric: name: bookers join_to_timespine: true fill_nulls_with: 0 - window: 2 days + cumulative_type_params: + window: 2 days --- metric: name: bookings_growth_2_weeks_fill_nulls_with_0 From 49d59e3f792bf3bccfea7d7a48fa1fae8f4313ca Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 13:15:42 -0700 Subject: [PATCH 09/13] Consume period_agg from configs --- .../simple_manifest/metrics.yaml | 3 +++ metricflow/plan_conversion/dataflow_to_sql.py | 16 +++++++++------- metricflow/sql/sql_exprs.py | 13 +++++++++++++ .../test_cases/itest_cumulative_metric.yaml | 6 +++--- .../test_cumulative_metric_rendering.py | 1 - ...ime_metric_with_non_default_grains__plan0.sql | 2 +- ..._with_non_default_grains__plan0_optimized.sql | 2 +- ...tive_metric_with_non_default_grain__plan0.sql | 2 +- ...c_with_non_default_grain__plan0_optimized.sql | 2 +- ...ive_metric_with_non_default_grains__plan0.sql | 6 +----- ..._with_non_default_grains__plan0_optimized.sql | 9 ++------- ...ndow_metric_with_non_default_grain__plan0.sql | 6 +----- ...c_with_non_default_grain__plan0_optimized.sql | 9 ++------- 13 files changed, 38 insertions(+), 39 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml index 4f65f5516b..e8f6a3100e 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml @@ -137,6 +137,7 @@ metric: measure: txn_revenue cumulative_type_params: window: 2 month + period_agg: average --- metric: name: "revenue_all_time" @@ -144,6 +145,8 @@ metric: type: cumulative type_params: measure: txn_revenue + cumulative_type_params: + period_agg: last --- metric: name: "every_two_days_bookers" diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index bf242e23b3..c3ad1d542f 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -10,6 +10,7 @@ from dbt_semantic_interfaces.references import EntityReference, MetricModelReference from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType from dbt_semantic_interfaces.type_enums.conversion_calculation_type import ConversionCalculationType +from dbt_semantic_interfaces.type_enums.period_agg import PeriodAggregation from dbt_semantic_interfaces.validations.unique_valid_name import MetricFlowReservedKeywords from metricflow_semantics.aggregation_properties import AggregationState from metricflow_semantics.dag.id_prefix import StaticIdPrefix @@ -1635,13 +1636,14 @@ def visit_window_reaggregation_node(self, node: WindowReaggregationNode) -> SqlD f"specs: {expected_specs}. Got: {parent_instance_set.as_tuple}." ) - # Pending DSI upgrade: - # sql_window_function = SqlWindowFunction[ - # self._metric_lookup.get_metric( - # metric_instance.spec.reference - # ).type_params.cumulative_type_params.period_agg.name - # ] - sql_window_function = SqlWindowFunction.FIRST_VALUE # placeholder for now + cumulative_type_params = self._metric_lookup.get_metric( + metric_instance.spec.reference + ).type_params.cumulative_type_params + sql_window_function = SqlWindowFunction.get_window_function_for_period_agg( + cumulative_type_params.period_agg + if cumulative_type_params and cumulative_type_params.period_agg + else PeriodAggregation.FIRST + ) order_by_args = [] if sql_window_function.requires_ordering: order_by_args.append( diff --git a/metricflow/sql/sql_exprs.py b/metricflow/sql/sql_exprs.py index 3e7d857f5a..f507bd2969 100644 --- a/metricflow/sql/sql_exprs.py +++ b/metricflow/sql/sql_exprs.py @@ -13,6 +13,7 @@ from dbt_semantic_interfaces.protocols.measure import MeasureAggregationParameters from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType from dbt_semantic_interfaces.type_enums.date_part import DatePart +from dbt_semantic_interfaces.type_enums.period_agg import PeriodAggregation from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix from metricflow_semantics.dag.mf_dag import DagNode, DisplayedProperty, NodeId @@ -967,6 +968,18 @@ def requires_ordering(self) -> bool: else: assert_values_exhausted(self) + @classmethod + def get_window_function_for_period_agg(cls, period_agg: PeriodAggregation) -> SqlWindowFunction: + """Get the window function to use for given period agg option.""" + if period_agg is PeriodAggregation.FIRST: + return cls.FIRST_VALUE + elif period_agg is PeriodAggregation.LAST: + return cls.LAST_VALUE + elif period_agg is PeriodAggregation.AVERAGE: + return cls.AVERAGE + else: + assert_values_exhausted(period_agg) + @dataclass(frozen=True) class SqlWindowOrderByArgument: diff --git a/tests_metricflow/integration/test_cases/itest_cumulative_metric.yaml b/tests_metricflow/integration/test_cases/itest_cumulative_metric.yaml index 1e8951f331..71c4cac228 100644 --- a/tests_metricflow/integration/test_cases/itest_cumulative_metric.yaml +++ b/tests_metricflow/integration/test_cases/itest_cumulative_metric.yaml @@ -428,7 +428,7 @@ integration_test: SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week, metric_time__quarter ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING @@ -467,7 +467,7 @@ integration_test: SELECT revenue_instance__ds__month , metric_time__week - , FIRST_VALUE(trailing_2_months_revenue) OVER ( + , AVG(trailing_2_months_revenue) OVER ( PARTITION BY revenue_instance__ds__month, metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING @@ -562,7 +562,7 @@ integration_test: SELECT metric_time__month , metric_time__year - , FIRST_VALUE(t2mr) OVER ( + , AVG(t2mr) OVER ( PARTITION BY metric_time__month, metric_time__year ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING diff --git a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py index 1724861a87..79da4c92b4 100644 --- a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py +++ b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py @@ -623,7 +623,6 @@ def test_derived_cumulative_metric_with_non_default_grains( # TODO: write the following tests when unblocked -# - Render each of the allowed period_aggs (both set in YAML & default) # - Query cumulative metric with non-day default_grain (using default grain and non-default grain) # - Query 2 metrics with different default_grains using metric_time (no grain specified) # - If default grain is WEEK, query with a higher grain (check that we still get correct values) 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 06946602ba..417d11e301 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 e23f35db1c..a83909ad88 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 87f1ee2560..95969c9da1 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 7dc86f44e7..a77fc38418 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 7ec0c9ba5d..cf6722d1ca 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 3dd1fa0855..b03d43632d 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine From d941ce323f372a357bc9ed4a8b66c1d52d3447c4 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 13:35:22 -0700 Subject: [PATCH 10/13] Update SQL engine snapshots --- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- ...st_all_time_metric_with_non_default_grains__plan0.sql | 2 +- ...e_metric_with_non_default_grains__plan0_optimized.sql | 2 +- ...t_cumulative_metric_with_non_default_grain__plan0.sql | 2 +- ...ve_metric_with_non_default_grain__plan0_optimized.sql | 2 +- ..._cumulative_metric_with_non_default_grains__plan0.sql | 6 +----- ...e_metric_with_non_default_grains__plan0_optimized.sql | 9 ++------- .../test_window_metric_with_non_default_grain__plan0.sql | 6 +----- ...ow_metric_with_non_default_grain__plan0_optimized.sql | 9 ++------- 48 files changed, 60 insertions(+), 168 deletions(-) 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 1db55b4fc8..a2f0fe2a62 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 ce1d77014a..b9a4fa76c0 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 249865fc7f..d3e05331c4 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 fb09e8107d..33aac00a24 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 eb21c43476..a216c5d3ef 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 46264148a0..f1f24ad9e2 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 59f20e1c18..b0558dd480 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 de0887fc7f..cb28189a09 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine 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 363fbac1f4..0638629bfb 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 a488d7de48..183461ce6a 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 4605df7ddf..f3f9badc38 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 77a5b962b8..1fc5274f31 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 cc3efae211..1b608ce209 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 fa117bbd01..40b3823c09 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine 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 06946602ba..417d11e301 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 e23f35db1c..a83909ad88 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 788402d146..d370d57659 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 0bfe669e27..e7c46e763c 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 45747e0d60..1a209eb763 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 39ebd683da..d7580282f7 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine 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 5dfff78486..29429e102b 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 fdcd0f72e9..803fc0e985 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 553faf9ffa..909304264a 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 77a5b962b8..1fc5274f31 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 3cc66160a7..c49c049b91 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 fa117bbd01..40b3823c09 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine 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 ddbc88d406..1c9a57d92b 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 13ba7d92b1..1e140d9bee 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 7324a7ff37..fe91f8515e 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 77a5b962b8..1fc5274f31 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 0d2de01365..5ff4e09f97 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 fa117bbd01..40b3823c09 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine 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 ae95312f90..8a5ddb3468 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 @@ -8,7 +8,7 @@ FROM ( SELECT subq_7.metric_time__week , subq_7.metric_time__quarter - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week , subq_7.metric_time__quarter 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 8b59f370ae..ea37c15884 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 @@ -8,7 +8,7 @@ FROM ( SELECT metric_time__week , metric_time__quarter - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week , metric_time__quarter 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 d46809a891..050b90fe7a 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.revenue_all_time) OVER ( + , LAST_VALUE(subq_7.revenue_all_time) OVER ( PARTITION BY subq_7.metric_time__week ORDER BY subq_7.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 6a6b6be266..2b6f12b36c 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 @@ -6,7 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(revenue_all_time) OVER ( + , LAST_VALUE(revenue_all_time) OVER ( PARTITION BY metric_time__week ORDER BY metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 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 b21242ba61..7a89445ace 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 @@ -11,11 +11,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__week - , FIRST_VALUE(subq_7.t2mr) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT 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 82044bf93b..7a01aa37b9 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 @@ -11,19 +11,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__week - , FIRST_VALUE(t2mr) OVER ( - PARTITION BY metric_time__week - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS t2mr + , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_12.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS t2mr FROM ( -- Time Spine 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 7d01df5097..06f1486ac1 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 @@ -6,11 +6,7 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT subq_7.metric_time__year - , FIRST_VALUE(subq_7.trailing_2_months_revenue) OVER ( - PARTITION BY subq_7.metric_time__year - ORDER BY subq_7.metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT 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 41d525603e..dd8e0518a4 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 @@ -6,19 +6,14 @@ FROM ( -- Window Function for Metric Re-aggregation SELECT metric_time__year - , FIRST_VALUE(trailing_2_months_revenue) OVER ( - PARTITION BY metric_time__year - ORDER BY metric_time__day - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS trailing_2_months_revenue + , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_11.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine From 29118c8d2f07ca79c9eed9fe1a711be51c75b720 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 16:16:54 -0700 Subject: [PATCH 11/13] Optimizer bug fix: don't remove select columns that are used in the group by Paul had a TODO up for this already, but this appears to be the first circumstance that made handling it necessary. --- .../optimizer/rewriting_sub_query_reducer.py | 27 +++++++++++++++---- ...th_non_default_grains__plan0_optimized.sql | 11 ++++---- ...ith_non_default_grain__plan0_optimized.sql | 11 ++++---- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/metricflow/sql/optimizer/rewriting_sub_query_reducer.py b/metricflow/sql/optimizer/rewriting_sub_query_reducer.py index 5d1eb7b6a5..18ffb95a99 100644 --- a/metricflow/sql/optimizer/rewriting_sub_query_reducer.py +++ b/metricflow/sql/optimizer/rewriting_sub_query_reducer.py @@ -240,7 +240,10 @@ def _current_node_can_be_reduced(self, node: SqlSelectStatementNode) -> bool: if len(parent_select_node.group_bys) > 0 and len(node.group_bys) > 0: return False - # TODO: Check for the following case: + # If there is a column in the parent group by that is not used in the current select statement, don't reduce or it + # would leave an unselected column in the group by and change the meaning of the query. For example, in the SQL + # below, reducing would remove the `is_instant` from the select statement. + # # SELECT # bookings # , 2 * bookings AS twice_bookings @@ -248,13 +251,27 @@ def _current_node_can_be_reduced(self, node: SqlSelectStatementNode) -> bool: # SELECT, # SUM(bookings) AS bookings # , fct_bookings_src.is_instant - # FROM ( - # SELECT * FROM demo.fct_bookings - # ) fct_bookings_src + # FROM demo.fct_bookings fct_bookings_src # GROUP BY fct_bookings_src.is_instant # ) src # - # If this is reduced, then the GROUP BY will refer to an unused column. + # Note: this is not as fine-tuned as it could be. This checks if all parent group bys are used in the current select + # columns as column reference expressions. If any are used in different types of expressions, we could reduce but + # won't. This is just limited by the complexity of different expressions that might be used. + current_select_column_refs = { + select_column.expr.as_column_reference_expression.col_ref.column_name + for select_column in node.select_columns + if select_column.expr.as_column_reference_expression + } + all_parent_group_bys_used_in_current_select = True + for group_by in parent_select_node.group_bys: + parent_group_by_select = SqlGroupByRewritingVisitor._find_matching_select( + expr=group_by.expr, select_columns=parent_select_node.select_columns + ) + if parent_group_by_select and parent_group_by_select.column_alias not in current_select_column_refs: + all_parent_group_bys_used_in_current_select = False + if not all_parent_group_bys_used_in_current_select: + return False # Don't reduce if the ORDER BYs aren't column reference expressions for simplicity. for order_by in node.order_bys: 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 a77fc38418..363d16e9bd 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 b03d43632d..03e4ba7fc4 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year From ad3e016ff1a3e999540dc4752d59c7decf400a7e Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 16:23:08 -0700 Subject: [PATCH 12/13] Update SQL engine snapshots --- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- ...etric_with_non_default_grains__plan0_optimized.sql | 11 ++++++----- ...metric_with_non_default_grain__plan0_optimized.sql | 11 ++++++----- 12 files changed, 72 insertions(+), 60 deletions(-) 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 f1f24ad9e2..8ceaaa47ac 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY metric_time__day , metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 cb28189a09..c1bbe03265 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY metric_time__day , metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year 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 1fc5274f31..94d66c8da0 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 40b3823c09..f2214f335f 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year 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 e7c46e763c..c1d8a4cf36 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 d7580282f7..960caea152 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year 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 1fc5274f31..94d66c8da0 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 40b3823c09..f2214f335f 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year 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 1fc5274f31..94d66c8da0 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 40b3823c09..f2214f335f 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year 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 7a01aa37b9..f052f1929e 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 @@ -8,18 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__week - , AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr + , AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + subq_12.metric_time__day AS metric_time__day + , subq_12.metric_time__week AS metric_time__week + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,7 +42,7 @@ FROM ( GROUP BY subq_12.metric_time__day , subq_12.metric_time__week - ) subq_17 + ) subq_16 ) subq_18 GROUP BY metric_time__week 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 dd8e0518a4..5d3f4efe05 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 @@ -3,18 +3,19 @@ SELECT metric_time__year , trailing_2_months_revenue FROM ( + -- Compute Metrics via Expressions -- Window Function for Metric Re-aggregation SELECT metric_time__year - , AVG(trailing_2_months_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue + , AVG(txn_revenue) OVER (PARTITION BY metric_time__year) AS trailing_2_months_revenue FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures - -- Compute Metrics via Expressions SELECT - subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__year AS metric_time__year + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -36,7 +37,7 @@ FROM ( GROUP BY subq_11.metric_time__day , subq_11.metric_time__year - ) subq_16 + ) subq_15 ) subq_17 GROUP BY metric_time__year From ef4f0a610acf432cd5fa0917c4f3041a4a8f3637 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 20 Jun 2024 16:28:42 -0700 Subject: [PATCH 13/13] Remove outdated comment --- metricflow-semantics/extra-hatch-configuration/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricflow-semantics/extra-hatch-configuration/requirements.txt b/metricflow-semantics/extra-hatch-configuration/requirements.txt index f574492e7b..6131ae86f3 100644 --- a/metricflow-semantics/extra-hatch-configuration/requirements.txt +++ b/metricflow-semantics/extra-hatch-configuration/requirements.txt @@ -1,5 +1,5 @@ # dbt Cloud depends on metricflow-semantics (dependency set in dbt-mantle), so DSI must always point to a production version here. -dbt-semantic-interfaces>=0.6.1, <2.0.0 # Temp: pin to dev release to support cumulative_type_params in MF before they get released in prod. +dbt-semantic-interfaces>=0.6.1, <2.0.0 graphviz>=0.18.2, <0.21 python-dateutil>=2.9.0, <2.10.0 rapidfuzz>=3.0, <4.0