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" diff --git a/extra-hatch-configuration/requirements.txt b/extra-hatch-configuration/requirements.txt index d48a78461f..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.0.dev2 +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 06d2516101..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.5.0, <2.0.0 +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 diff --git a/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py b/metricflow-semantics/metricflow_semantics/model/dbt_manifest_parser.py index ea1ba90c9c..638da5283f 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 ( @@ -25,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(),), @@ -35,6 +37,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) 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/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..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 @@ -135,7 +135,9 @@ metric: type: cumulative type_params: measure: txn_revenue - window: 2 month + cumulative_type_params: + window: 2 month + period_agg: average --- metric: name: "revenue_all_time" @@ -143,6 +145,8 @@ metric: type: cumulative type_params: measure: txn_revenue + cumulative_type_params: + period_agg: last --- metric: name: "every_two_days_bookers" @@ -158,7 +162,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 +634,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 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 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/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/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/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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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_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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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/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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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_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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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_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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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_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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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_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..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,23 +8,19 @@ FROM ( metric_time__week , t2mr FROM ( + -- Compute Metrics via Expressions -- 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(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__day AS metric_time__day , subq_12.metric_time__week AS metric_time__week - , SUM(revenue_src_28000.revenue) AS t2mr + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -46,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.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..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,23 +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 - , 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(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__day AS metric_time__day , subq_11.metric_time__year AS metric_time__year - , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue + , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT @@ -41,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