From 3d5bdbe4eb61f0f4a389ee289697333669ae4629 Mon Sep 17 00:00:00 2001 From: tlento Date: Tue, 3 Sep 2024 12:04:51 -0700 Subject: [PATCH] Use ExpandedTimeGranularity in TimeDimensionSpec In order to support custom granularities we need a way to propagate them through the dataflow plan building and plan conversion processes. We typically use the TimeDimensionSpec classes for carrying that information, since the specs indicate the grain of the specific variation of the TimeDimension element we're operating on. We decided to use an ExpandedTimeGranularity construct to encapsulate the custom granularity metadata in a manner interchangeable with the default granularity enumeration values, with the idea that these would make it more obvious when and how to do comparisons and things. This change updates the TimeDimensionSpec itself to use the new construct. The changes here are meant to be as mechanical as possible, so there are places where restructuring or follow-up is needed. It was not possible to do purely mechanical changes in all cases. --- .../model/semantics/linkable_element_set.py | 2 +- .../naming/dunder_scheme.py | 2 +- .../naming/object_builder_str.py | 23 +- .../candidate_push_down/push_down_visitor.py | 2 + .../group_by_item/group_by_item_resolver.py | 4 +- .../query/query_parser.py | 2 +- .../specs/non_additive_dimension_spec.py | 17 +- .../specs/patterns/entity_link_pattern.py | 21 +- .../metric_time_default_granularity.py | 8 +- .../specs/patterns/minimum_time_grain.py | 13 +- .../specs/time_dimension_spec.py | 20 +- .../test_helpers/metric_time_dimension.py | 21 +- .../metricflow_semantics/time/granularity.py | 20 +- .../collection_helpers/test_pretty_print.py | 16 +- .../semantics/test_linkable_element_set.py | 2 +- .../model/test_where_filter_spec.py | 20 +- .../naming/conftest.py | 3 +- .../naming/test_dunder_naming_scheme.py | 5 +- .../test_object_builder_naming_scheme.py | 5 +- ..._rate_with_constant_properties__result.txt | 7 +- ...ccumulate_last_2_months_metric__result.txt | 5 +- ...h_different_parent_time_grains__result.txt | 5 +- ...c_with_same_parent_time_grains__result.txt | 5 +- ...ics_with_different_time_grains__result.txt | 5 +- ..._metrics_with_same_time_grains__result.txt | 5 +- ...me_in_query_filter__no_metrics__result.txt | 5 +- ...in_query_filter__simple_metric__result.txt | 5 +- ...th_explicit_time_granularity__result_0.txt | 7 +- ...ut_explicit_time_granularity__result_0.txt | 7 +- ..._ignores_default_granularity__result_0.txt | 2 +- ...th_explicit_time_granularity__result_0.txt | 7 +- ...ut_explicit_time_granularity__result_0.txt | 7 +- ...time_dimension_name_validation__result.txt | 2 +- ...ved_metric_with_offset_parsing__result.txt | 7 +- ...rder_by_granularity_conversion__result.txt | 15 +- ...r_by_granularity_no_conversion__result.txt | 15 +- ...validate_where_constraint_dims__result.txt | 7 +- .../test_query_parser__result.txt | 15 +- ..._case_insensitivity_with_names__result.txt | 15 +- ...itivity_with_parameter_objects__result.txt | 15 +- ...uery_parser_with_object_params__result.txt | 15 +- ...me_range_constraint_conversion__result.txt | 7 +- .../patterns/test_entity_link_pattern.py | 5 +- .../specs/patterns/test_typed_patterns.py | 13 +- .../specs/test_spec_serialization.py | 2 +- .../specs/test_time_dimension_spec.py | 10 +- .../tests_metricflow_semantics/test_specs.py | 11 +- .../dataflow/builder/dataflow_plan_builder.py | 22 +- metricflow/dataflow/builder/partitions.py | 11 +- metricflow/dataset/convert_semantic_model.py | 3 +- metricflow/dataset/dataset_classes.py | 9 +- metricflow/plan_conversion/dataflow_to_sql.py | 56 ++- .../plan_conversion/instance_converters.py | 12 +- .../plan_conversion/sql_join_builder.py | 11 +- .../builder/test_dataflow_plan_builder.py | 3 +- .../dataflow/builder/test_node_evaluator.py | 7 +- tests_metricflow/examples/test_node_sql.py | 7 +- .../test_conversion_metrics_to_sql.py | 13 +- ...create_validity_window_join_description.py | 9 +- .../test_dataflow_to_sql_plan.py | 30 +- .../test_cumulative_metric_rendering.py | 21 +- .../test_granularity_date_part_rendering.py | 7 +- .../test_metric_time_without_metrics.py | 5 +- .../query_rendering/test_query_rendering.py | 5 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 8 +- ...and_fill_nulls_with_0__plan0_optimized.sql | 26 +- ...timespine_and_fill_nulls_with_0__plan0.xml | 18 +- ..._metric_with_non_default_grains__plan0.sql | 4 +- ...th_non_default_grains__plan0_optimized.sql | 4 +- ..._no_window_with_time_constraint__plan0.sql | 4 +- ..._with_time_constraint__plan0_optimized.sql | 4 +- ...c_with_agg_time_and_metric_time__plan0.sql | 4 +- ..._time_and_metric_time__plan0_optimized.sql | 4 +- ..._metric_with_agg_time_dimension__plan0.sql | 4 +- ...th_agg_time_dimension__plan0_optimized.sql | 17 +- ...th_multiple_agg_time_dimensions__plan0.sql | 4 +- ...e_agg_time_dimensions__plan0_optimized.sql | 4 +- ...multiple_metric_time_dimensions__plan0.sql | 4 +- ...etric_time_dimensions__plan0_optimized.sql | 4 +- ...with_non_adjustable_time_filter__plan0.sql | 4 +- ...djustable_time_filter__plan0_optimized.sql | 15 +- ...e_metric_with_non_default_grain__plan0.sql | 4 +- ...ith_non_default_grain__plan0_optimized.sql | 4 +- ...ive_metric_with_time_constraint__plan0.sql | 4 +- ..._with_time_constraint__plan0_optimized.sql | 4 +- ..._metric_with_non_default_grains__plan0.sql | 4 +- ...th_non_default_grains__plan0_optimized.sql | 4 +- ...e_metric_with_non_default_grain__plan0.sql | 4 +- ...ith_non_default_grain__plan0_optimized.sql | 4 +- ..._metric_with_non_default_grains__plan0.sql | 4 +- ...th_non_default_grains__plan0_optimized.sql | 4 +- ...w_metric_with_non_default_grain__plan0.sql | 4 +- ...ith_non_default_grain__plan0_optimized.sql | 4 +- ..._metric_with_non_default_grains__plan0.sql | 8 +- ...th_non_default_grains__plan0_optimized.sql | 19 +- .../test_common_semantic_model__dfp_0.xml | 24 +- ...indow_or_grain_with_metric_time__dfp_0.xml | 15 +- ...e_metric_with_non_default_grain__dfp_0.xml | 42 +- ...t_cumulative_metric_with_window__dfp_0.xml | 15 +- ...e_metric_with_non_default_grain__dfp_0.xml | 42 +- ..._derived_metric_offset_to_grain__dfp_0.xml | 21 +- ...st_derived_metric_offset_window__dfp_0.xml | 15 +- ..._metric_offset_with_granularity__dfp_0.xml | 15 +- ...erived_offset_cumulative_metric__dfp_0.xml | 24 +- ...dimensions_with_time_constraint__dfp_0.xml | 12 +- ...in_to_time_spine_derived_metric__dfp_0.xml | 39 +- ...join_to_time_spine_with_filters__dfp_0.xml | 31 +- ..._to_time_spine_with_metric_time__dfp_0.xml | 15 +- ...time_spine_with_non_metric_time__dfp_0.xml | 12 +- .../test_limit_rows_plan__dfp_0.xml | 6 +- .../test_measure_constraint_plan__dfp_0.xml | 52 ++- ...traint_with_reused_measure_plan__dfp_0.xml | 19 +- .../test_metric_time_only__dfp_0.xml | 6 +- .../test_metric_time_quarter__dfp_0.xml | 6 +- ...tric_time_with_other_dimensions__dfp_0.xml | 24 +- .../test_min_max_metric_time__dfp_0.xml | 6 +- .../test_min_max_metric_time_week__dfp_0.xml | 6 +- .../test_min_max_only_time__dfp_0.xml | 12 +- .../test_min_max_only_time_year__dfp_0.xml | 12 +- ...mantic_model_ratio_metrics_plan__dfp_0.xml | 26 +- .../test_multihop_join_plan__dfp_0.xml | 388 ++++++++++-------- .../test_multiple_metrics_plan__dfp_0.xml | 12 +- ...erived_metric_with_outer_offset__dfp_0.xml | 24 +- ...ry_have_different_granularities__dfp_0.xml | 46 ++- ...ry_have_different_granularities__dfp_0.xml | 83 +++- .../test_order_by_plan__dfp_0.xml | 19 +- ...mantic_model_ratio_metrics_plan__dfp_0.xml | 26 +- ...constrained_plan_time_dimension__dfp_0.xml | 16 +- ...spine_node_with_offset_to_grain__plan0.xml | 15 +- ...e_spine_node_with_offset_window__plan0.xml | 15 +- ..._time_spine_node_without_offset__plan0.xml | 15 +- ...spine_node_with_offset_to_grain__plan0.sql | 4 +- ..._with_offset_to_grain__plan0_optimized.sql | 4 +- ...e_spine_node_with_offset_window__plan0.sql | 4 +- ...de_with_offset_window__plan0_optimized.sql | 4 +- ..._time_spine_node_without_offset__plan0.sql | 4 +- ...e_node_without_offset__plan0_optimized.sql | 4 +- ...spine_node_with_offset_to_grain__plan0.xml | 4 +- ...e_spine_node_with_offset_window__plan0.xml | 4 +- ..._time_spine_node_without_offset__plan0.xml | 4 +- ...set_metric_with_time_constraint__plan0.sql | 8 +- ..._with_time_constraint__plan0_optimized.sql | 19 +- ...ved_metric_with_offset_to_grain__plan0.sql | 4 +- ..._with_offset_to_grain__plan0_optimized.sql | 15 +- ...offset_to_grain_and_granularity__plan0.sql | 4 +- ...grain_and_granularity__plan0_optimized.sql | 17 +- ...rived_metric_with_offset_window__plan0.sql | 4 +- ...ic_with_offset_window__plan0_optimized.sql | 15 +- ...h_offset_window_and_granularity__plan0.sql | 4 +- ...indow_and_granularity__plan0_optimized.sql | 15 +- ...fset_window_and_offset_to_grain__plan0.sql | 8 +- ...w_and_offset_to_grain__plan0_optimized.sql | 30 +- ...offset_to_grain_and_granularity__plan0.sql | 8 +- ...grain_and_granularity__plan0_optimized.sql | 32 +- ...h_offset_window_and_time_filter__plan0.sql | 4 +- ...indow_and_time_filter__plan0_optimized.sql | 13 +- ...erived_offset_cumulative_metric__plan0.sql | 8 +- ...set_cumulative_metric__plan0_optimized.sql | 30 +- ...offset_metric_with_agg_time_dim__plan0.sql | 4 +- ...ric_with_agg_time_dim__plan0_optimized.sql | 15 +- ...et_metric_with_one_input_metric__plan0.sql | 4 +- ...with_one_input_metric__plan0_optimized.sql | 15 +- ...d_where_constraint_not_selected__plan0.sql | 8 +- ...nstraint_not_selected__plan0_optimized.sql | 28 +- ...h_offset_multiple_input_metrics__plan0.sql | 4 +- ...ultiple_input_metrics__plan0_optimized.sql | 13 +- .../DuckDB/test_nested_offsets__plan0.sql | 8 +- .../test_nested_offsets__plan0_optimized.sql | 28 +- ...ed_offsets_with_time_constraint__plan0.sql | 8 +- ..._with_time_constraint__plan0_optimized.sql | 19 +- ...d_offsets_with_where_constraint__plan0.sql | 8 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 4 +- ...fferent_granularities__plan0_optimized.sql | 17 +- ...n_metric_multiple_granularities__plan0.sql | 4 +- ...ultiple_granularities__plan0_optimized.sql | 23 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 4 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 15 +- ...ry_have_different_granularities__plan0.sql | 4 +- ...fferent_granularities__plan0_optimized.sql | 15 +- ...w_metric_multiple_granularities__plan0.sql | 4 +- ...ultiple_granularities__plan0_optimized.sql | 23 +- ...offset_window_with_agg_time_dim__plan0.sql | 4 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 15 +- ...set_metric_with_time_constraint__plan0.sql | 4 +- ..._with_time_constraint__plan0_optimized.sql | 4 +- .../test_cumulative_fill_nulls__plan0.sql | 8 +- ...cumulative_fill_nulls__plan0_optimized.sql | 30 +- ...fill_nulls_for_one_input_metric__plan0.sql | 8 +- ..._for_one_input_metric__plan0_optimized.sql | 28 +- ...join_to_time_spine_with_filters__plan0.sql | 4 +- ...me_spine_with_filters__plan0_optimized.sql | 4 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 4 +- ...ls_with_0_metric_time__plan0_optimized.sql | 13 +- ...st_offset_window_with_date_part__plan0.sql | 4 +- ...window_with_date_part__plan0_optimized.sql | 15 +- ...cumulative_grain_to_date_metric__plan0.sql | 4 +- ..._grain_to_date_metric__plan0_optimized.sql | 17 +- ...bdaily_cumulative_window_metric__plan0.sql | 4 +- ...ulative_window_metric__plan0_optimized.sql | 17 +- ...ides_metric_default_granularity__plan0.sql | 4 +- ...c_default_granularity__plan0_optimized.sql | 13 +- ...daily_join_to_time_spine_metric__plan0.sql | 4 +- ..._to_time_spine_metric__plan0_optimized.sql | 13 +- ...subdaily_offset_to_grain_metric__plan0.sql | 4 +- ...ffset_to_grain_metric__plan0_optimized.sql | 15 +- ...t_subdaily_offset_window_metric__plan0.sql | 4 +- ..._offset_window_metric__plan0_optimized.sql | 15 +- ...ily_time_constraint_with_metric__plan0.sql | 4 +- ...onstraint_with_metric__plan0_optimized.sql | 4 +- ...rsion_metric_predicate_pushdown__dfp_0.xml | 67 ++- ...sion_metric_predicate_pushdown__dfpo_0.xml | 64 ++- ...ative_metric_predicate_pushdown__dfp_0.xml | 31 +- ...tive_metric_predicate_pushdown__dfpo_0.xml | 27 +- ...spine_metric_predicate_pushdown__dfp_0.xml | 87 +++- ...pine_metric_predicate_pushdown__dfpo_0.xml | 84 +++- ...ost_agg_join_predicate_pushdown__dfp_0.xml | 75 +++- ...st_agg_join_predicate_pushdown__dfpo_0.xml | 72 +++- ...ffset_metric_predicate_pushdown__dfp_0.xml | 63 ++- ...fset_metric_predicate_pushdown__dfpo_0.xml | 62 ++- ..._time_pushdown_with_two_targets__dfp_0.xml | 23 +- ...time_pushdown_with_two_targets__dfpo_0.xml | 23 +- ..._metric_with_query_time_filters__plan0.sql | 4 +- ...th_query_time_filters__plan0_optimized.sql | 15 +- ...spine_metric_predicate_pushdown__plan0.sql | 12 +- ...ic_predicate_pushdown__plan0_optimized.sql | 39 +- ..._metric_with_query_time_filters__plan0.sql | 4 +- ...th_query_time_filters__plan0_optimized.sql | 13 +- ...ine_pushdown_filter_application__plan0.sql | 4 +- ...wn_filter_application__plan0_optimized.sql | 13 +- ...2_metrics_from_1_semantic_model__dfp_0.xml | 24 +- ..._metrics_from_1_semantic_model__dfpo_0.xml | 12 +- ..._metrics_from_2_semantic_models__dfp_0.xml | 12 +- ...metrics_from_2_semantic_models__dfpo_0.xml | 12 +- ...o_metrics_from_1_semantic_model__dfp_0.xml | 24 +- ..._metrics_from_1_semantic_model__dfpo_0.xml | 6 +- ..._metrics_from_2_semantic_models__dfp_0.xml | 18 +- ...metrics_from_2_semantic_models__dfpo_0.xml | 12 +- ...constrained_metric_not_combined__dfp_0.xml | 18 +- ...onstrained_metric_not_combined__dfpo_0.xml | 18 +- .../test_derived_metric__dfp_0.xml | 12 +- .../test_derived_metric__dfpo_0.xml | 6 +- ..._metric_with_non_derived_metric__dfp_0.xml | 18 +- ...metric_with_non_derived_metric__dfpo_0.xml | 12 +- .../test_duplicate_measures__dfp_0.xml | 12 +- .../test_duplicate_measures__dfpo_0.xml | 6 +- .../test_nested_derived_metric__dfp_0.xml | 26 +- .../test_nested_derived_metric__dfpo_0.xml | 12 +- ...ne_with_queried_time_constraint__plan0.sql | 4 +- ...eried_time_constraint__plan0_optimized.sql | 4 +- .../test_simple_join_to_time_spine__plan0.sql | 4 +- ...le_join_to_time_spine__plan0_optimized.sql | 13 +- ..._join_to_time_spine_with_filter__plan0.sql | 4 +- ...ime_spine_with_filter__plan0_optimized.sql | 13 +- ..._time_spine_with_queried_filter__plan0.sql | 4 +- ...e_with_queried_filter__plan0_optimized.sql | 13 +- 256 files changed, 2918 insertions(+), 1053 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element_set.py b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element_set.py index b82af877fa..ca95288d04 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element_set.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element_set.py @@ -360,7 +360,7 @@ def _path_key_to_spec(path_key: ElementPathKey) -> LinkableInstanceSpec: return TimeDimensionSpec( element_name=path_key.element_name, entity_links=path_key.entity_links, - time_granularity=path_key.time_granularity.base_granularity, + time_granularity=path_key.time_granularity, date_part=path_key.date_part, ) elif path_key.element_type is LinkableElementType.ENTITY: diff --git a/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py b/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py index 8f1424a8cb..e0e3c69711 100644 --- a/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py +++ b/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py @@ -154,7 +154,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]: if time_dimension_spec.date_part is not None: items.append(DunderNamingScheme.date_part_suffix(date_part=time_dimension_spec.date_part)) else: - items.append(time_dimension_spec.time_granularity.value) + items.append(time_dimension_spec.time_granularity.name) names_to_return.append(DUNDER.join(items)) for other_group_by_item_specs in ( diff --git a/metricflow-semantics/metricflow_semantics/naming/object_builder_str.py b/metricflow-semantics/metricflow_semantics/naming/object_builder_str.py index 75095ed56f..3810bf34ed 100644 --- a/metricflow-semantics/metricflow_semantics/naming/object_builder_str.py +++ b/metricflow-semantics/metricflow_semantics/naming/object_builder_str.py @@ -10,7 +10,6 @@ ) from dbt_semantic_interfaces.naming.keywords import DUNDER from dbt_semantic_interfaces.references import EntityReference -from dbt_semantic_interfaces.type_enums import TimeGranularity from dbt_semantic_interfaces.type_enums.date_part import DatePart from typing_extensions import override @@ -32,7 +31,7 @@ def input_str_from_entity_call_parameter_set(parameter_set: EntityCallParameterS element_name=parameter_set.entity_reference.element_name, entity_links=parameter_set.entity_path, group_by=(), - time_granularity=None, + time_granularity_name=None, date_part=None, ) return f"Entity({initializer_parameter_str})" @@ -45,7 +44,7 @@ def input_str_from_metric_call_parameter_set(parameter_set: MetricCallParameterS group_by=tuple( EntityReference(element_name=group_by_ref.element_name) for group_by_ref in parameter_set.group_by ), - time_granularity=None, + time_granularity_name=None, date_part=None, ) return f"Metric({initializer_parameter_str})" @@ -55,7 +54,7 @@ def initializer_parameter_str( element_name: str, entity_links: Sequence[EntityReference], group_by: Sequence[EntityReference], - time_granularity: Optional[TimeGranularity], + time_granularity_name: Optional[str], date_part: Optional[DatePart], ) -> str: """Return the parameters that should go in the initializer. @@ -68,9 +67,9 @@ def initializer_parameter_str( initializer_parameters.append(repr(entity_link_names[-1] + DUNDER + element_name)) else: initializer_parameters.append(repr(element_name)) - if time_granularity is not None: + if time_granularity_name is not None: initializer_parameters.append( - f"'{time_granularity.value}'", + f"'{time_granularity_name}'", ) if date_part is not None: initializer_parameters.append(f"date_part_name={repr(date_part.value)}") @@ -101,7 +100,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]: element_name=entity_spec.element_name, entity_links=entity_spec.entity_links, group_by=(), - time_granularity=None, + time_granularity_name=None, date_part=None, ) names_to_return.append(f"Entity({initializer_parameter_str})") @@ -111,7 +110,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]: element_name=dimension_spec.element_name, entity_links=dimension_spec.entity_links, group_by=(), - time_granularity=None, + time_granularity_name=None, date_part=None, ) names_to_return.append(f"Dimension({initializer_parameter_str})") @@ -121,7 +120,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]: element_name=time_dimension_spec.element_name, entity_links=time_dimension_spec.entity_links, group_by=(), - time_granularity=time_dimension_spec.time_granularity, + time_granularity_name=time_dimension_spec.time_granularity.name, date_part=time_dimension_spec.date_part, ) names_to_return.append(f"TimeDimension({initializer_parameter_str})") @@ -131,7 +130,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]: element_name=group_by_metric_spec.element_name, entity_links=(), group_by=group_by_metric_spec.entity_links, - time_granularity=None, + time_granularity_name=None, date_part=None, ) names_to_return.append(f"Metric({initializer_parameter_str})") @@ -153,7 +152,7 @@ def input_str_from_dimension_call_parameter_set(parameter_set: DimensionCallPara element_name=parameter_set.dimension_reference.element_name, entity_links=parameter_set.entity_path, group_by=(), - time_granularity=None, + time_granularity_name=None, date_part=None, ) return f"Dimension({initializer_parameter_str})" @@ -166,7 +165,7 @@ def input_str_from_time_dimension_call_parameter_set( # noqa: D102 element_name=parameter_set.time_dimension_reference.element_name, entity_links=parameter_set.entity_path, group_by=(), - time_granularity=None, + time_granularity_name=None, date_part=None, ) return f"TimeDimension({initializer_parameter_str})" diff --git a/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py b/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py index 0e37559b90..5f5b691146 100644 --- a/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py +++ b/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py @@ -67,6 +67,8 @@ class PushDownResult: # The issues seen so far while pushing down the result / resolving the ambiguity. issue_set: MetricFlowQueryResolutionIssueSet # The largest default time granularity of the metrics seen in the DAG so far. Used to resolve metric_time. + # TODO: [custom granularity] decide whether or not to support custom granularities as metric_time defaults and + # update accordingly max_metric_default_time_granularity: Optional[TimeGranularity] = None def __post_init__(self) -> None: # noqa: D105 diff --git a/metricflow-semantics/metricflow_semantics/query/group_by_item/group_by_item_resolver.py b/metricflow-semantics/metricflow_semantics/query/group_by_item/group_by_item_resolver.py index 542c3d6976..09c2475387 100644 --- a/metricflow-semantics/metricflow_semantics/query/group_by_item/group_by_item_resolver.py +++ b/metricflow-semantics/metricflow_semantics/query/group_by_item/group_by_item_resolver.py @@ -226,7 +226,7 @@ def resolve_available_items( ) def resolve_min_metric_time_grain(self) -> TimeGranularity: - """Returns the finest time grain of metric_time for querying.""" + """Returns the finest base time grain of metric_time for querying.""" metric_time_grain_resolution = self.resolve_matching_item_for_querying( spec_pattern=TimeDimensionPattern.from_call_parameter_set( TimeDimensionCallParameterSet( @@ -247,4 +247,4 @@ def resolve_min_metric_time_grain(self) -> TimeGranularity: f"{metric_time_grain_resolution.spec} and issues:\n\n" f"{indent(mf_pformat(metric_time_grain_resolution.issue_set))}" ) - return metric_time_spec_set.time_dimension_specs[0].time_granularity + return metric_time_spec_set.time_dimension_specs[0].time_granularity.base_granularity diff --git a/metricflow-semantics/metricflow_semantics/query/query_parser.py b/metricflow-semantics/metricflow_semantics/query/query_parser.py index 6613f69761..d9ca3f81ef 100644 --- a/metricflow-semantics/metricflow_semantics/query/query_parser.py +++ b/metricflow-semantics/metricflow_semantics/query/query_parser.py @@ -166,7 +166,7 @@ def _get_smallest_requested_metric_time_granularity( len(time_dimension_specs) == 1 ), f"Bug with MinimumTimeGrainPattern - should have returned exactly 1 spec but got {time_dimension_specs}" - return time_dimension_specs[0].time_granularity + return time_dimension_specs[0].time_granularity.base_granularity def _adjust_time_constraint( self, diff --git a/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py b/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py index 78eb3df0ff..295c526af2 100644 --- a/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py +++ b/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py @@ -12,6 +12,7 @@ from metricflow_semantics.specs.instance_spec import LinkableInstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.sql.sql_column_type import SqlColumnType +from metricflow_semantics.time.granularity import ExpandedTimeGranularity def hash_items(items: Sequence[SqlColumnType]) -> str: @@ -48,11 +49,19 @@ def bucket_hash(self) -> str: values.extend(sorted(self.window_groupings)) return hash_items(values) - def linkable_specs( # noqa: D102 - self, non_additive_dimension_grain: TimeGranularity - ) -> Sequence[LinkableInstanceSpec]: + def linkable_specs(self, non_additive_dimension_grain: TimeGranularity) -> Sequence[LinkableInstanceSpec]: + """Return the set of linkable specs referenced by the NonAdditiveDimensionSpec. + + In practice, the name will always point to a time dimension. This method requires the time granularity + provided in the model Dimension definition, which is why the input is typed as an enum value rather than + an expanded granularity object - custom granularities are not eligible for consideration here. + """ return ( - TimeDimensionSpec(element_name=self.name, entity_links=(), time_granularity=non_additive_dimension_grain), + TimeDimensionSpec( + element_name=self.name, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(non_additive_dimension_grain), + ), ) + tuple(LinklessEntitySpec.from_element_name(entity_name) for entity_name in self.window_groupings) def __eq__(self, other: Any) -> bool: # type: ignore[misc] # noqa: D105 diff --git a/metricflow-semantics/metricflow_semantics/specs/patterns/entity_link_pattern.py b/metricflow-semantics/metricflow_semantics/specs/patterns/entity_link_pattern.py index 72034d65c1..ce7f970ad9 100644 --- a/metricflow-semantics/metricflow_semantics/specs/patterns/entity_link_pattern.py +++ b/metricflow-semantics/metricflow_semantics/specs/patterns/entity_link_pattern.py @@ -112,6 +112,22 @@ def _match_entity_links(self, candidate_specs: Sequence[LinkableInstanceSpec]) - shortest_entity_link_length = min(len(matching_spec.entity_links) for matching_spec in matching_specs) return tuple(spec for spec in matching_specs if len(spec.entity_links) == shortest_entity_link_length) + def _match_time_granularities( + self, candidate_specs: Sequence[LinkableInstanceSpec] + ) -> Sequence[LinkableInstanceSpec]: + """Do a partial match on time granularities. + + TODO: [custom granularity] Support custom granularities properly. This requires us to allow these pattern classes + to take in ExpandedTimeGranularity types, which should be viable. Once that is done, this method can be removed. + """ + matching_specs: Sequence[LinkableInstanceSpec] = tuple( + candidate_spec + for candidate_spec in group_specs_by_type(candidate_specs).time_dimension_specs + if candidate_spec.time_granularity.base_granularity == self.parameter_set.time_granularity + ) + + return matching_specs + @override def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[LinkableInstanceSpec]: filtered_candidate_specs = group_specs_by_type(candidate_specs).linkable_specs @@ -120,10 +136,13 @@ def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[LinkableIns # Entity links could be a partial match, so it's handled separately. if ParameterSetField.ENTITY_LINKS in self.parameter_set.fields_to_compare: filtered_candidate_specs = self._match_entity_links(filtered_candidate_specs) + # Time granularities are special, so they are also handled separately. + if ParameterSetField.TIME_GRANULARITY in self.parameter_set.fields_to_compare: + filtered_candidate_specs = self._match_time_granularities(filtered_candidate_specs) other_keys_to_check = set( field_to_compare.value for field_to_compare in self.parameter_set.fields_to_compare - ).difference({ParameterSetField.ENTITY_LINKS.value}) + ).difference({ParameterSetField.ENTITY_LINKS.value, ParameterSetField.TIME_GRANULARITY.value}) matching_specs: List[LinkableInstanceSpec] = [] parameter_set_values = tuple(getattr(self.parameter_set, key_to_check) for key_to_check in other_keys_to_check) diff --git a/metricflow-semantics/metricflow_semantics/specs/patterns/metric_time_default_granularity.py b/metricflow-semantics/metricflow_semantics/specs/patterns/metric_time_default_granularity.py index 8c3a2499f1..eb273a221b 100644 --- a/metricflow-semantics/metricflow_semantics/specs/patterns/metric_time_default_granularity.py +++ b/metricflow-semantics/metricflow_semantics/specs/patterns/metric_time_default_granularity.py @@ -15,6 +15,7 @@ TimeDimensionSpecComparisonKey, TimeDimensionSpecField, ) +from metricflow_semantics.time.granularity import ExpandedTimeGranularity class MetricTimeDefaultGranularityPattern(SpecPattern): @@ -53,9 +54,12 @@ def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[InstanceSpe return candidate_specs # If there are metrics in the query, use max metric default. For no-metric queries, use standard default. - default_granularity = self._max_metric_default_time_granularity or DEFAULT_TIME_GRANULARITY + # TODO: [custom granularity] allow custom granularities to be used as defaults if appropriate + default_granularity = ExpandedTimeGranularity.from_time_granularity( + self._max_metric_default_time_granularity or DEFAULT_TIME_GRANULARITY + ) - spec_key_to_grains: Dict[TimeDimensionSpecComparisonKey, Set[TimeGranularity]] = defaultdict(set) + spec_key_to_grains: Dict[TimeDimensionSpecComparisonKey, Set[ExpandedTimeGranularity]] = defaultdict(set) spec_key_to_specs: Dict[TimeDimensionSpecComparisonKey, Tuple[TimeDimensionSpec, ...]] = defaultdict(tuple) for metric_time_spec in spec_set.metric_time_specs: spec_key = metric_time_spec.comparison_key(exclude_fields=(TimeDimensionSpecField.TIME_GRANULARITY,)) diff --git a/metricflow-semantics/metricflow_semantics/specs/patterns/minimum_time_grain.py b/metricflow-semantics/metricflow_semantics/specs/patterns/minimum_time_grain.py index 13fee8f24c..ce76718fb6 100644 --- a/metricflow-semantics/metricflow_semantics/specs/patterns/minimum_time_grain.py +++ b/metricflow-semantics/metricflow_semantics/specs/patterns/minimum_time_grain.py @@ -14,10 +14,11 @@ TimeDimensionSpecComparisonKey, TimeDimensionSpecField, ) +from metricflow_semantics.time.granularity import ExpandedTimeGranularity class MinimumTimeGrainPattern(SpecPattern): - """A pattern that matches linkable specs, but for time dimension specs, only the one with the finest grain. + """A pattern that matches linkable specs, but for time dimension specs, only the one with the finest base grain. e.g. @@ -35,7 +36,7 @@ class MinimumTimeGrainPattern(SpecPattern): ] The finest grain represents the defined grain of the time dimension in the semantic model when evaluating specs - of the source. + of the source. For custom granularities, this means the base grain associated with the time dimension spec. This pattern helps to implement matching of group-by-items for where filters - in those cases, an ambiguously specified group-by-item can only match to time dimension spec with the base grain. @@ -49,12 +50,16 @@ def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[InstanceSpe spec_key_to_specs: Dict[TimeDimensionSpecComparisonKey, List[TimeDimensionSpec]] = defaultdict(list) for time_dimension_spec in spec_set.time_dimension_specs: spec_key = time_dimension_spec.comparison_key(exclude_fields=(TimeDimensionSpecField.TIME_GRANULARITY,)) - spec_key_to_grains[spec_key].add(time_dimension_spec.time_granularity) + spec_key_to_grains[spec_key].add(time_dimension_spec.time_granularity.base_granularity) spec_key_to_specs[spec_key].append(time_dimension_spec) matched_time_dimension_specs: List[TimeDimensionSpec] = [] for spec_key, time_grains in spec_key_to_grains.items(): - matched_time_dimension_specs.append(spec_key_to_specs[spec_key][0].with_grain(min(time_grains))) + matched_time_dimension_specs.append( + spec_key_to_specs[spec_key][0].with_grain( + ExpandedTimeGranularity.from_time_granularity(min(time_grains)) + ) + ) matching_specs: Sequence[LinkableInstanceSpec] = ( spec_set.dimension_specs diff --git a/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py b/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py index 38aa979733..94b2561cb5 100644 --- a/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py +++ b/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py @@ -50,7 +50,7 @@ def __init__(self, source_spec: TimeDimensionSpec, exclude_fields: Sequence[Time # This is a list of field values of TimeDimensionSpec that we should use for comparison. spec_field_values_for_comparison: List[ - Union[str, Tuple[EntityReference, ...], TimeGranularity, Optional[DatePart]] + Union[str, Tuple[EntityReference, ...], ExpandedTimeGranularity, Optional[DatePart]] ] = [self._source_spec.element_name, self._source_spec.entity_links] if TimeDimensionSpecField.TIME_GRANULARITY not in self._excluded_fields: @@ -84,7 +84,7 @@ def __hash__(self) -> int: @dataclass(frozen=True) class TimeDimensionSpec(DimensionSpec): # noqa: D101 - time_granularity: TimeGranularity = DEFAULT_TIME_GRANULARITY + time_granularity: ExpandedTimeGranularity = ExpandedTimeGranularity.from_time_granularity(DEFAULT_TIME_GRANULARITY) date_part: Optional[DatePart] = None # Used for semi-additive joins. Some more thought is needed, but this may be useful in InstanceSpec. @@ -122,7 +122,7 @@ def qualified_name(self) -> str: # noqa: D102 return StructuredLinkableSpecName( entity_link_names=tuple(x.element_name for x in self.entity_links), element_name=self.element_name, - time_granularity_name=self.time_granularity.value, + time_granularity_name=self.time_granularity.name, date_part=self.date_part, ).qualified_name @@ -133,7 +133,7 @@ def element_path_key(self) -> ElementPathKey: element_name=self.element_name, element_type=LinkableElementType.TIME_DIMENSION, entity_links=self.entity_links, - time_granularity=ExpandedTimeGranularity.from_time_granularity(self.time_granularity), + time_granularity=self.time_granularity, date_part=self.date_part, ) @@ -145,7 +145,7 @@ def from_reference(reference: TimeDimensionReference) -> TimeDimensionSpec: def accept(self, visitor: InstanceSpecVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 return visitor.visit_time_dimension_spec(self) - def with_grain(self, time_granularity: TimeGranularity) -> TimeDimensionSpec: # noqa: D102 + def with_grain(self, time_granularity: ExpandedTimeGranularity) -> TimeDimensionSpec: # noqa: D102 return TimeDimensionSpec( element_name=self.element_name, entity_links=self.entity_links, @@ -174,14 +174,18 @@ def comparison_key(self, exclude_fields: Sequence[TimeDimensionSpecField] = ()) def generate_possible_specs_for_time_dimension( time_dimension_reference: TimeDimensionReference, entity_links: Tuple[EntityReference, ...] ) -> List[TimeDimensionSpec]: - """Generate a list of time dimension specs with all combinations of granularity & date part.""" + """Generate a list of time dimension specs with all combinations of granularity & date part. + + TODO: [custom calendar] decide whether to add support for custom granularities or rename this to indicate that + it only includes standard granularities. + """ time_dimension_specs: List[TimeDimensionSpec] = [] for time_granularity in TimeGranularity: time_dimension_specs.append( TimeDimensionSpec( element_name=time_dimension_reference.element_name, entity_links=entity_links, - time_granularity=time_granularity, + time_granularity=ExpandedTimeGranularity.from_time_granularity(time_granularity), date_part=None, ) ) @@ -191,7 +195,7 @@ def generate_possible_specs_for_time_dimension( TimeDimensionSpec( element_name=time_dimension_reference.element_name, entity_links=entity_links, - time_granularity=time_granularity, + time_granularity=ExpandedTimeGranularity.from_time_granularity(time_granularity), date_part=date_part, ) ) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/metric_time_dimension.py b/metricflow-semantics/metricflow_semantics/test_helpers/metric_time_dimension.py index 090e5abd0e..5f9accaebc 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/metric_time_dimension.py +++ b/metricflow-semantics/metricflow_semantics/test_helpers/metric_time_dimension.py @@ -5,22 +5,33 @@ from dbt_semantic_interfaces.validations.unique_valid_name import MetricFlowReservedKeywords from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity # Shortcuts for referring to the metric time dimension. MTD = MetricFlowReservedKeywords.METRIC_TIME.value MTD_REFERENCE = TimeDimensionReference(element_name=MetricFlowReservedKeywords.METRIC_TIME.value) MTD_SPEC_DAY = TimeDimensionSpec( - element_name=MetricFlowReservedKeywords.METRIC_TIME.value, entity_links=(), time_granularity=TimeGranularity.DAY + element_name=MetricFlowReservedKeywords.METRIC_TIME.value, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) MTD_SPEC_WEEK = TimeDimensionSpec( - element_name=MetricFlowReservedKeywords.METRIC_TIME.value, entity_links=(), time_granularity=TimeGranularity.WEEK + element_name=MetricFlowReservedKeywords.METRIC_TIME.value, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), ) MTD_SPEC_MONTH = TimeDimensionSpec( - element_name=MetricFlowReservedKeywords.METRIC_TIME.value, entity_links=(), time_granularity=TimeGranularity.MONTH + element_name=MetricFlowReservedKeywords.METRIC_TIME.value, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ) MTD_SPEC_QUARTER = TimeDimensionSpec( - element_name=MetricFlowReservedKeywords.METRIC_TIME.value, entity_links=(), time_granularity=TimeGranularity.QUARTER + element_name=MetricFlowReservedKeywords.METRIC_TIME.value, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.QUARTER), ) MTD_SPEC_YEAR = TimeDimensionSpec( - element_name=MetricFlowReservedKeywords.METRIC_TIME.value, entity_links=(), time_granularity=TimeGranularity.YEAR + element_name=MetricFlowReservedKeywords.METRIC_TIME.value, + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.YEAR), ) diff --git a/metricflow-semantics/metricflow_semantics/time/granularity.py b/metricflow-semantics/metricflow_semantics/time/granularity.py index 98d14ca00f..cf036b869c 100644 --- a/metricflow-semantics/metricflow_semantics/time/granularity.py +++ b/metricflow-semantics/metricflow_semantics/time/granularity.py @@ -11,17 +11,27 @@ class ExpandedTimeGranularity(SerializableDataclass): """Dataclass container for custom granularity extensions to the base TimeGranularity enumeration. This includes the granularity name, which is either the custom granularity or the TimeGranularity string value, - and an associated base time granularity value which we use as a pointer to the base grain used to look up the - time spine. This will allow for some level of comparison between custom granularities. + and an associated base time granularity value. - Note: this assumes that any base TimeGranularity value will derive the name from the TimeGranularity. It might be - worth adding validation to ensure that is always the case, meaning that no `name` value can be a value in the - TimeGranularity enumeration. + For custom granularities, we use the base time granularity as a pointer to the base standard grain used to look + up the time spine. For standard TimeGranularities the base_granularity is always the same as the TimeGranularity. + + This will allow us to continue to do comparisons for standard TimeGranularity values, and also to do some level of + comparison between custom granularities. """ name: str base_granularity: TimeGranularity + def __post_init__(self) -> None: + """Post init validation to ensure this class is configured correctly for standard time granularity values.""" + if ExpandedTimeGranularity.is_standard_granularity_name(self.name): + assert TimeGranularity(self.name) == self.base_granularity, ( + f"Invalid configuration of ExpandedTimeGranularity for standard TimeGranularity with name {self.name}." + f"This should correspond to a base_granularity of {TimeGranularity(self.name)}, but it has " + f"{self.base_granularity}." + ) + @property def is_custom_granularity(self) -> bool: # noqa: D102 return self.base_granularity.value != self.name diff --git a/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py b/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py index 364032c0ed..f01c9891b4 100644 --- a/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py +++ b/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py @@ -30,7 +30,7 @@ def test_containers() -> None: # noqa: D103 def test_classes() -> None: # noqa: D103 - assert "TimeDimensionSpec('metric_time', DAY)" == mf_pformat( + assert "TimeDimensionSpec('metric_time', ExpandedTimeGranularity('day', DAY))" == mf_pformat( MTD_SPEC_DAY, include_object_field_names=False, include_none_object_fields=False, @@ -43,7 +43,7 @@ def test_classes() -> None: # noqa: D103 TimeDimensionSpec( element_name='metric_time', entity_links=(), - time_granularity=DAY, + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), date_part=None, aggregation_state=None, ) @@ -57,7 +57,17 @@ def test_classes() -> None: # noqa: D103 ) ) - assert "TimeDimensionSpec(element_name='metric_time', time_granularity=DAY)" == mf_pformat(MTD_SPEC_DAY) + assert ( + textwrap.dedent( + """\ + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ) + """ + ).rstrip() + == mf_pformat(MTD_SPEC_DAY) + ) def test_multi_line_key_value_dict() -> None: diff --git a/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py b/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py index 936a51519b..e77cf67654 100644 --- a/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py +++ b/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py @@ -713,7 +713,7 @@ def test_filter_by_pattern(linkable_set: LinkableElementSet) -> None: TimeDimensionSpec( element_name="time_dimension_element", entity_links=(EntityReference("entity_1"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=None, ), ) diff --git a/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py b/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py index 154955b459..0fe5ea58e5 100644 --- a/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py +++ b/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py @@ -160,7 +160,7 @@ def test_dimension_in_filter_with_grain( # noqa: D103 resolved_spec=TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference("listing"),), - time_granularity=TimeGranularity.WEEK, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), ), resolved_linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ @@ -202,7 +202,7 @@ def test_dimension_in_filter_with_grain( # noqa: D103 TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference(element_name="listing"),), - time_granularity=TimeGranularity.WEEK, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), ), ), entity_specs=(), @@ -224,7 +224,7 @@ def test_time_dimension_in_filter( # noqa: D103 resolved_spec=TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference("listing"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), resolved_linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ @@ -266,7 +266,7 @@ def test_time_dimension_in_filter( # noqa: D103 TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference(element_name="listing"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), entity_specs=(), @@ -288,7 +288,7 @@ def test_time_dimension_with_grain_in_name( # noqa: D103 resolved_spec=TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference("listing"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), resolved_linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ @@ -330,7 +330,7 @@ def test_time_dimension_with_grain_in_name( # noqa: D103 TimeDimensionSpec( element_name="created_at", entity_links=(EntityReference(element_name="listing"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), entity_specs=(), @@ -352,7 +352,7 @@ def test_date_part_in_filter( # noqa: D103 resolved_spec=TimeDimensionSpec( element_name="metric_time", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=DatePart.YEAR, ), resolved_linkable_element_set=LinkableElementSet( @@ -395,7 +395,7 @@ def test_date_part_in_filter( # noqa: D103 TimeDimensionSpec( element_name="metric_time", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=DatePart.YEAR, ), ), @@ -483,7 +483,7 @@ def test_date_part_and_grain_in_filter( # noqa: D103 TimeDimensionSpec( element_name="metric_time", entity_links=(), - time_granularity=TimeGranularity.WEEK, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), date_part=DatePart.YEAR, ), ), @@ -520,7 +520,7 @@ def test_date_part_less_than_grain_in_filter( # noqa: D103 TimeDimensionSpec( element_name="metric_time", entity_links=(), - time_granularity=TimeGranularity.WEEK, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), date_part=DatePart.DAY, ), ), diff --git a/metricflow-semantics/tests_metricflow_semantics/naming/conftest.py b/metricflow-semantics/tests_metricflow_semantics/naming/conftest.py index 90b63a1812..9dc15c0c48 100644 --- a/metricflow-semantics/tests_metricflow_semantics/naming/conftest.py +++ b/metricflow-semantics/tests_metricflow_semantics/naming/conftest.py @@ -12,6 +12,7 @@ from metricflow_semantics.specs.instance_spec import LinkableInstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_MONTH, MTD_SPEC_WEEK, MTD_SPEC_YEAR +from metricflow_semantics.time.granularity import ExpandedTimeGranularity @pytest.fixture(scope="session") @@ -24,7 +25,7 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.DAY, ), # Dimensions diff --git a/metricflow-semantics/tests_metricflow_semantics/naming/test_dunder_naming_scheme.py b/metricflow-semantics/tests_metricflow_semantics/naming/test_dunder_naming_scheme.py index 4835a86265..981476cfcc 100644 --- a/metricflow-semantics/tests_metricflow_semantics/naming/test_dunder_naming_scheme.py +++ b/metricflow-semantics/tests_metricflow_semantics/naming/test_dunder_naming_scheme.py @@ -12,6 +12,7 @@ from metricflow_semantics.specs.instance_spec import LinkableInstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_MONTH, MTD_SPEC_WEEK, MTD_SPEC_YEAR +from metricflow_semantics.time.granularity import ExpandedTimeGranularity @pytest.fixture(scope="session") @@ -38,7 +39,7 @@ def test_input_str(dunder_naming_scheme: DunderNamingScheme) -> None: # noqa: D TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference(element_name="booking"), EntityReference(element_name="listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.DAY, ) ) @@ -53,7 +54,7 @@ def test_input_str(dunder_naming_scheme: DunderNamingScheme) -> None: # noqa: D EntityReference(element_name="booking"), EntityReference(element_name="listing"), ), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ) ) == "booking__listing__creation_time__month" diff --git a/metricflow-semantics/tests_metricflow_semantics/naming/test_object_builder_naming_scheme.py b/metricflow-semantics/tests_metricflow_semantics/naming/test_object_builder_naming_scheme.py index 209f6e51c7..8416c935e1 100644 --- a/metricflow-semantics/tests_metricflow_semantics/naming/test_object_builder_naming_scheme.py +++ b/metricflow-semantics/tests_metricflow_semantics/naming/test_object_builder_naming_scheme.py @@ -13,6 +13,7 @@ from metricflow_semantics.specs.instance_spec import LinkableInstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_MONTH, MTD_SPEC_WEEK, MTD_SPEC_YEAR +from metricflow_semantics.time.granularity import ExpandedTimeGranularity @pytest.fixture(scope="session") @@ -35,7 +36,7 @@ def test_input_str(object_builder_naming_scheme: ObjectBuilderNamingScheme) -> N TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference(element_name="booking"), EntityReference(element_name="listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.DAY, ) ) == ("TimeDimension('listing__creation_time', 'month', date_part_name='day', entity_path=['booking'])") @@ -102,7 +103,7 @@ def test_spec_pattern( # noqa: D103 TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.DAY, ), ) diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt index 7eec0e4d6c..c898b56f44 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt @@ -11,7 +11,12 @@ ParseQueryResult( entity_links=(EntityReference(element_name='user'),), ), ), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__accumulate_last_2_months_metric__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__accumulate_last_2_months_metric__result.txt index 19b1e65d1d..1a85f227b6 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__accumulate_last_2_months_metric__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__accumulate_last_2_months_metric__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_different_parent_time_grains__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_different_parent_time_grains__result.txt index cd50b4c1dc..a6d94b9099 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_different_parent_time_grains__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_different_parent_time_grains__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=YEAR), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='year', base_granularity=YEAR), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_same_parent_time_grains__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_same_parent_time_grains__result.txt index 19b1e65d1d..1a85f227b6 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_same_parent_time_grains__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__derived_metric_with_same_parent_time_grains__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_different_time_grains__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_different_time_grains__result.txt index cd50b4c1dc..a6d94b9099 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_different_time_grains__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_different_time_grains__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=YEAR), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='year', base_granularity=YEAR), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_same_time_grains__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_same_time_grains__result.txt index 19b1e65d1d..1a85f227b6 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_same_time_grains__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__metrics_with_same_time_grains__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__no_metrics__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__no_metrics__result.txt index 209ac018ef..49ed9dcd91 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__no_metrics__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__no_metrics__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__simple_metric__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__simple_metric__result.txt index 19b1e65d1d..1a85f227b6 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__simple_metric__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_matching_item_for_filters.py/GroupByItemResolution/test_ambiguous_metric_time_in_query_filter__simple_metric__result.txt @@ -1,5 +1,8 @@ GroupByItemResolution( - spec=TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH), + spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), linkable_element_set=LinkableElementSet( path_key_to_linkable_dimensions={ ElementPathKey( diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_explicit_time_granularity__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_explicit_time_granularity__result_0.txt index 1cbbd0e8be..58dc086594 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_explicit_time_granularity__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_explicit_time_granularity__result_0.txt @@ -1,6 +1,11 @@ MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='derived_metric_with_time_granularity'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=YEAR),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='year', base_granularity=YEAR), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_without_explicit_time_granularity__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_without_explicit_time_granularity__result_0.txt index e128590790..ff0b339306 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_without_explicit_time_granularity__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_without_explicit_time_granularity__result_0.txt @@ -1,6 +1,11 @@ MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='derived_metric_without_time_granularity'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_non_metric_time_ignores_default_granularity__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_non_metric_time_ignores_default_granularity__result_0.txt index a009b6c10d..c4864012a5 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_non_metric_time_ignores_default_granularity__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_non_metric_time_ignores_default_granularity__result_0.txt @@ -4,7 +4,7 @@ MetricFlowQuerySpec( TimeDimensionSpec( element_name='ds', entity_links=(EntityReference(element_name='listing'),), - time_granularity=DAY, + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), ), ), filter_intersection=PydanticWhereFilterIntersection(), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_with_explicit_time_granularity__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_with_explicit_time_granularity__result_0.txt index 56b55e7f8c..b9e283b935 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_with_explicit_time_granularity__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_with_explicit_time_granularity__result_0.txt @@ -1,6 +1,11 @@ MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='largest_listing'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_without_explicit_time_granularity__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_without_explicit_time_granularity__result_0.txt index e4e886ec47..d848239171 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_without_explicit_time_granularity__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_simple_metric_without_explicit_time_granularity__result_0.txt @@ -1,6 +1,11 @@ MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='monthly_metric_0'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_cumulative_metric_agg_time_dimension_name_validation__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_cumulative_metric_agg_time_dimension_name_validation__result.txt index fb49793461..ec8d7bf0a9 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_cumulative_metric_agg_time_dimension_name_validation__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_cumulative_metric_agg_time_dimension_name_validation__result.txt @@ -5,7 +5,7 @@ ParseQueryResult( TimeDimensionSpec( element_name='ds', entity_links=(EntityReference(element_name='revenue_instance'),), - time_granularity=MONTH, + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), ), ), filter_intersection=PydanticWhereFilterIntersection(), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_derived_metric_with_offset_parsing__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_derived_metric_with_offset_parsing__result.txt index 4f6c6cb998..692c379b99 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_derived_metric_with_offset_parsing__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_derived_metric_with_offset_parsing__result.txt @@ -1,7 +1,12 @@ ParseQueryResult( query_spec=MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='revenue_growth_2_weeks'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), filter_intersection=PydanticWhereFilterIntersection(), filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), min_max_only=False, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_conversion__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_conversion__result.txt index d64d104f5d..87ca579f36 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_conversion__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_conversion__result.txt @@ -1,10 +1,21 @@ ParseQueryResult( query_spec=MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='bookings'), MetricSpec(element_name='revenue')), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='month', + base_granularity=MONTH, + ), + ), descending=True, ), ), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_no_conversion__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_no_conversion__result.txt index ae5ca2ae13..526506e5c3 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_no_conversion__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_order_by_granularity_no_conversion__result.txt @@ -1,10 +1,21 @@ ParseQueryResult( query_spec=MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='bookings'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='day', + base_granularity=DAY, + ), + ), descending=False, ), ), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_parse_and_validate_where_constraint_dims__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_parse_and_validate_where_constraint_dims__result.txt index bd0765d8e1..5506daedf7 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_parse_and_validate_where_constraint_dims__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_parse_and_validate_where_constraint_dims__result.txt @@ -1,7 +1,12 @@ ParseQueryResult( query_spec=MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='bookings'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), time_range_constraint=TimeRangeConstraint( start_time=datetime.datetime(2020, 1, 15, 0, 0), end_time=datetime.datetime(2020, 2, 15, 0, 0), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser__result.txt index fd62a4611f..14216fc428 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser__result.txt @@ -8,10 +8,21 @@ ParseQueryResult( ), ), entity_specs=(EntitySpec(element_name='listing'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='day', + base_granularity=DAY, + ), + ), descending=False, ), OrderBySpec(instance_spec=MetricSpec(element_name='bookings'), descending=True), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_names__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_names__result.txt index fd62a4611f..14216fc428 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_names__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_names__result.txt @@ -8,10 +8,21 @@ ParseQueryResult( ), ), entity_specs=(EntitySpec(element_name='listing'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='day', + base_granularity=DAY, + ), + ), descending=False, ), OrderBySpec(instance_spec=MetricSpec(element_name='bookings'), descending=True), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_parameter_objects__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_parameter_objects__result.txt index fd62a4611f..14216fc428 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_parameter_objects__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_case_insensitivity_with_parameter_objects__result.txt @@ -8,10 +8,21 @@ ParseQueryResult( ), ), entity_specs=(EntitySpec(element_name='listing'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='day', + base_granularity=DAY, + ), + ), descending=False, ), OrderBySpec(instance_spec=MetricSpec(element_name='bookings'), descending=True), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_with_object_params__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_with_object_params__result.txt index fd62a4611f..14216fc428 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_with_object_params__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_query_parser_with_object_params__result.txt @@ -8,10 +8,21 @@ ParseQueryResult( ), ), entity_specs=(EntitySpec(element_name='listing'),), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='day', base_granularity=DAY), + ), + ), order_by_specs=( OrderBySpec( - instance_spec=TimeDimensionSpec(element_name='metric_time', time_granularity=DAY), + instance_spec=TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity( + name='day', + base_granularity=DAY, + ), + ), descending=False, ), OrderBySpec(instance_spec=MetricSpec(element_name='bookings'), descending=True), diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_time_range_constraint_conversion__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_time_range_constraint_conversion__result.txt index e7c2d2cd60..95cab878bd 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_time_range_constraint_conversion__result.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_query_parser.py/ParseQueryResult/test_time_range_constraint_conversion__result.txt @@ -1,7 +1,12 @@ ParseQueryResult( query_spec=MetricFlowQuerySpec( metric_specs=(MetricSpec(element_name='bookings'), MetricSpec(element_name='revenue')), - time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), + time_dimension_specs=( + TimeDimensionSpec( + element_name='metric_time', + time_granularity=ExpandedTimeGranularity(name='month', base_granularity=MONTH), + ), + ), time_range_constraint=TimeRangeConstraint( start_time=datetime.datetime(2020, 1, 1, 0, 0), end_time=datetime.datetime(2020, 2, 29, 0, 0), diff --git a/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_entity_link_pattern.py b/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_entity_link_pattern.py index 617802cb41..a917a575b8 100644 --- a/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_entity_link_pattern.py +++ b/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_entity_link_pattern.py @@ -20,6 +20,7 @@ ) from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_MONTH, MTD_SPEC_WEEK, MTD_SPEC_YEAR +from metricflow_semantics.time.granularity import ExpandedTimeGranularity logger = logging.getLogger(__name__) @@ -34,7 +35,7 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.YEAR, ), # Dimensions @@ -215,7 +216,7 @@ def test_time_dimension_date_part_match(specs: Sequence[LinkableInstanceSpec]) - TimeDimensionSpec( element_name="creation_time", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), date_part=DatePart.YEAR, ), ) diff --git a/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_typed_patterns.py b/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_typed_patterns.py index f74e748669..fb70a37ac1 100644 --- a/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_typed_patterns.py +++ b/metricflow-semantics/tests_metricflow_semantics/specs/patterns/test_typed_patterns.py @@ -29,6 +29,7 @@ TimeDimensionPattern, ) from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity logger = logging.getLogger(__name__) @@ -40,13 +41,13 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=None, ), TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=DatePart.MONTH, ), # Dimensions @@ -84,13 +85,13 @@ def test_dimension_pattern(specs: Sequence[LinkableInstanceSpec]) -> None: # no TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=None, ), TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=DatePart.MONTH, ), ) @@ -108,7 +109,7 @@ def test_time_dimension_pattern(specs: Sequence[LinkableInstanceSpec]) -> None: TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=None, ), ) @@ -127,7 +128,7 @@ def test_time_dimension_pattern_with_date_part(specs: Sequence[LinkableInstanceS TimeDimensionSpec( element_name="common_name", entity_links=(EntityReference("booking"), EntityReference("listing")), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), date_part=DatePart.MONTH, ), ) diff --git a/metricflow-semantics/tests_metricflow_semantics/specs/test_spec_serialization.py b/metricflow-semantics/tests_metricflow_semantics/specs/test_spec_serialization.py index 0dc0d8a252..294cbc1c2b 100644 --- a/metricflow-semantics/tests_metricflow_semantics/specs/test_spec_serialization.py +++ b/metricflow-semantics/tests_metricflow_semantics/specs/test_spec_serialization.py @@ -61,7 +61,7 @@ def test_where_filter_spec_serialization() -> None: # noqa: D103 TimeDimensionSpec( element_name="element_name", entity_links=(EntityReference(element_name="element_name"),), - time_granularity=TimeGranularity.YEAR, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.YEAR), ), ), entity_specs=( diff --git a/metricflow-semantics/tests_metricflow_semantics/specs/test_time_dimension_spec.py b/metricflow-semantics/tests_metricflow_semantics/specs/test_time_dimension_spec.py index 1417025038..8e4180bfe3 100644 --- a/metricflow-semantics/tests_metricflow_semantics/specs/test_time_dimension_spec.py +++ b/metricflow-semantics/tests_metricflow_semantics/specs/test_time_dimension_spec.py @@ -5,6 +5,7 @@ from dbt_semantic_interfaces.references import EntityReference from dbt_semantic_interfaces.type_enums import TimeGranularity from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec, TimeDimensionSpecField +from metricflow_semantics.time.granularity import ExpandedTimeGranularity logger = logging.getLogger(__name__) @@ -13,13 +14,13 @@ def test_comparison_key_excluding_time_grain() -> None: # noqa: D103 spec0 = TimeDimensionSpec( element_name="element0", entity_links=(EntityReference("entity0"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) spec1 = TimeDimensionSpec( element_name="element0", entity_links=(EntityReference("entity0"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ) assert spec0.comparison_key(exclude_fields=[]) != spec1.comparison_key(exclude_fields=[]) assert spec0.comparison_key(exclude_fields=[]) != spec1.comparison_key((TimeDimensionSpecField.TIME_GRANULARITY,)) @@ -30,4 +31,7 @@ def test_comparison_key_excluding_time_grain() -> None: # noqa: D103 spec1.comparison_key(exclude_fields=[TimeDimensionSpecField.TIME_GRANULARITY]) ) - assert spec0.with_grain(TimeGranularity.MONTH).comparison_key() == spec1.comparison_key() + assert ( + spec0.with_grain(ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH)).comparison_key() + == spec1.comparison_key() + ) diff --git a/metricflow-semantics/tests_metricflow_semantics/test_specs.py b/metricflow-semantics/tests_metricflow_semantics/test_specs.py index 85f31c2037..5c4ee91ec5 100644 --- a/metricflow-semantics/tests_metricflow_semantics/test_specs.py +++ b/metricflow-semantics/tests_metricflow_semantics/test_specs.py @@ -13,6 +13,7 @@ from metricflow_semantics.specs.metric_spec import MetricSpec from metricflow_semantics.specs.spec_set import InstanceSpecSet from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity @pytest.fixture @@ -31,7 +32,7 @@ def time_dimension_spec() -> TimeDimensionSpec: # noqa: D103 return TimeDimensionSpec( element_name="signup_ts", entity_links=(EntityReference(element_name="user_id"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) @@ -62,7 +63,7 @@ def test_time_dimension_without_first_entity_link(time_dimension_spec: TimeDimen assert time_dimension_spec.without_first_entity_link == TimeDimensionSpec( element_name="signup_ts", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) @@ -127,7 +128,7 @@ def spec_set() -> InstanceSpecSet: # noqa: D103 TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), entity_specs=( @@ -152,7 +153,7 @@ def test_spec_set_linkable_specs(spec_set: InstanceSpecSet) -> None: # noqa: D1 TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), EntitySpec( element_name="user_id", @@ -176,7 +177,7 @@ def test_spec_set_all_specs(spec_set: InstanceSpecSet) -> None: # noqa: D103 TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), EntitySpec( element_name="user_id", diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index a0477f857a..43e01476db 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -54,6 +54,7 @@ from metricflow_semantics.sql.sql_join_type import SqlJoinType from metricflow_semantics.sql.sql_table import SqlTable from metricflow_semantics.time.dateutil_adjuster import DateutilTimePeriodAdjuster +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.node_data_set import DataflowPlanNodeOutputDataSetResolver from metricflow.dataflow.builder.node_evaluator import ( @@ -438,7 +439,10 @@ def _build_cumulative_metric_output_node( predicate_pushdown_state: PredicatePushdownState, for_group_by_source_node: bool = False, ) -> DataflowPlanNode: - default_granularity = self._metric_lookup.get_min_queryable_time_granularity(metric_spec.reference) + # TODO: [custom granularity] Figure out how to support custom granularities as defaults + default_granularity = ExpandedTimeGranularity.from_time_granularity( + self._metric_lookup.get_min_queryable_time_granularity(metric_spec.reference) + ) queried_agg_time_dimensions = queried_linkable_specs.included_agg_time_dimension_specs_for_metric( metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup @@ -462,7 +466,7 @@ def _build_cumulative_metric_output_node( # once as a normal metric, and again using a window function to narrow down to one row per granularity period. # In this case, add metric time at the default granularity to the linkable specs. It will be used in the order by # clause of the window function and later excluded from the output selections. - default_metric_time = DataSet.metric_time_dimension_spec(default_granularity) + default_metric_time = DataSet.metric_time_dimension_spec(default_granularity.base_granularity) include_linkable_specs = queried_linkable_specs.merge( LinkableSpecSet(time_dimension_specs=(default_metric_time,)) ) @@ -1556,18 +1560,18 @@ def _build_aggregated_measure_from_measure_source_node( non_additive_dimension_grain = self._semantic_model_lookup.get_defined_time_granularity( TimeDimensionReference(non_additive_dimension_spec.name) ) - queried_time_dimension_spec: Optional[ - TimeDimensionSpec - ] = self._find_non_additive_dimension_in_linkable_specs( - agg_time_dimension=agg_time_dimension, - linkable_specs=queried_linkable_specs.as_tuple, - non_additive_dimension_spec=non_additive_dimension_spec, + queried_time_dimension_spec: Optional[TimeDimensionSpec] = ( + self._find_non_additive_dimension_in_linkable_specs( + agg_time_dimension=agg_time_dimension, + linkable_specs=queried_linkable_specs.as_tuple, + non_additive_dimension_spec=non_additive_dimension_spec, + ) ) time_dimension_spec = TimeDimensionSpec( # The NonAdditiveDimensionSpec name property is a plain element name element_name=non_additive_dimension_spec.name, entity_links=(), - time_granularity=non_additive_dimension_grain, + time_granularity=ExpandedTimeGranularity.from_time_granularity(non_additive_dimension_grain), ) window_groupings = tuple( LinklessEntitySpec.from_element_name(name) for name in non_additive_dimension_spec.window_groupings diff --git a/metricflow/dataflow/builder/partitions.py b/metricflow/dataflow/builder/partitions.py index 599c8a7faa..7222100f7a 100644 --- a/metricflow/dataflow/builder/partitions.py +++ b/metricflow/dataflow/builder/partitions.py @@ -98,7 +98,16 @@ def resolve_partition_dimension_joins( def _get_simplest_time_dimension_spec(time_dimension_specs: Sequence[TimeDimensionSpec]) -> TimeDimensionSpec: """Return the time dimension spec with the smallest granularity, then fewest entity links.""" assert len(time_dimension_specs) > 0 - sorted_specs = sorted(time_dimension_specs, key=lambda x: (x.time_granularity, len(x.entity_links))) + # TODO: [custom granularity] restructure this method to operate on partition collections instead, and + # move this enforcement to the PartitionSpecSet + assert all(not x.time_granularity.is_custom_granularity for x in time_dimension_specs), ( + f"Found custom granularity in partition time dimension specs {time_dimension_specs}, but time partitions " + "can only use standard granularities as they are based on engine date/time types!" + ) + + sorted_specs = sorted( + time_dimension_specs, key=lambda x: (x.time_granularity.base_granularity, len(x.entity_links)) + ) return sorted_specs[0] def resolve_partition_time_dimension_joins( diff --git a/metricflow/dataset/convert_semantic_model.py b/metricflow/dataset/convert_semantic_model.py index e1de4b1258..067c5855af 100644 --- a/metricflow/dataset/convert_semantic_model.py +++ b/metricflow/dataset/convert_semantic_model.py @@ -33,6 +33,7 @@ from metricflow_semantics.specs.entity_spec import EntitySpec from metricflow_semantics.specs.time_dimension_spec import DEFAULT_TIME_GRANULARITY, TimeDimensionSpec from metricflow_semantics.sql.sql_table import SqlTable +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow_semantics.time.time_spine_source import TIME_SPINE_DATA_SET_DESCRIPTION, TimeSpineSource from metricflow.dataset.semantic_model_adapter import SemanticModelDataSet @@ -112,7 +113,7 @@ def _create_time_dimension_instance( time_dimension_spec = TimeDimensionSpec( element_name=element_name, entity_links=entity_links, - time_granularity=time_granularity, + time_granularity=ExpandedTimeGranularity.from_time_granularity(time_granularity), date_part=date_part, ) diff --git a/metricflow/dataset/dataset_classes.py b/metricflow/dataset/dataset_classes.py index c2a822e42d..3b052b5c1a 100644 --- a/metricflow/dataset/dataset_classes.py +++ b/metricflow/dataset/dataset_classes.py @@ -10,6 +10,7 @@ from dbt_semantic_interfaces.validations.unique_valid_name import MetricFlowReservedKeywords from metricflow_semantics.instances import InstanceSet, TimeDimensionInstance from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity logger = logging.getLogger(__name__) @@ -52,11 +53,15 @@ def metric_time_dimension_name() -> str: def metric_time_dimension_spec( time_granularity: TimeGranularity, date_part: Optional[DatePart] = None ) -> TimeDimensionSpec: - """Spec that corresponds to DataSet.metric_time_dimension_reference.""" + """Spec that corresponds to DataSet.metric_time_dimension_reference. + + This is currently used for source time dimension specs derived directly from a semantic model, so + custom granularities are not available at the points where this method is invoked. + """ return TimeDimensionSpec( element_name=DataSet.metric_time_dimension_reference().element_name, entity_links=(), - time_granularity=time_granularity, + time_granularity=ExpandedTimeGranularity.from_time_granularity(time_granularity), date_part=date_part, ) diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 712118dfac..322f754be8 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -245,11 +245,16 @@ def _choose_time_spine_source( - Time spines available: SECOND, MINUTE, DAY - Agg time dimension granularity needed for request: HOUR, DAY --> Selected time spine: MINUTE + + Note time spines are identified by the base granularity from the time dimension instance, not the raw granularity + name. """ assert ( agg_time_dimension_instances ), "Building time spine dataset requires agg_time_dimension_instances, but none were found." - smallest_agg_time_grain = min(dim.spec.time_granularity for dim in agg_time_dimension_instances) + smallest_agg_time_grain = min( + dim.spec.time_granularity.base_granularity for dim in agg_time_dimension_instances + ) compatible_time_spine_grains = [ grain for grain in self._time_spine_sources.keys() if grain.to_int() <= smallest_agg_time_grain.to_int() ] @@ -287,10 +292,13 @@ def _make_time_spine_data_set( select_columns += (SqlSelectColumn(expr=column_expr, column_alias=column_alias),) # If any columns have a different granularity, apply a DATE_TRUNC() and aggregate via group_by. else: + agg_time_grain = agg_time_dimension_instance.spec.time_granularity + # TODO: [custom granularity] add support for custom granularities to make_time_spine_data_set + assert not agg_time_grain.is_custom_granularity, "Custom time granularities are not yet supported!" select_columns += ( SqlSelectColumn( expr=SqlDateTruncExpression.create( - time_granularity=agg_time_dimension_instance.spec.time_granularity, arg=column_expr + time_granularity=agg_time_grain.base_granularity, arg=column_expr ), column_alias=column_alias, ), @@ -331,15 +339,15 @@ def visit_join_over_time_range_node(self, node: JoinOverTimeRangeNode) -> SqlDat input_data_set_alias = self._next_unique_table_alias() # Find requested agg_time_dimensions in parent instance set. - # Will use instance with smallest granularity in time spine join. + # Will use instance with smallest base granularity in time spine join. agg_time_dimension_instance_for_join: Optional[TimeDimensionInstance] = None requested_agg_time_dimension_instances: Tuple[TimeDimensionInstance, ...] = () for instance in input_data_set.instance_set.time_dimension_instances: if instance.spec in node.queried_agg_time_dimension_specs: requested_agg_time_dimension_instances += (instance,) if not agg_time_dimension_instance_for_join or ( - instance.spec.time_granularity.to_int() - < agg_time_dimension_instance_for_join.spec.time_granularity.to_int() + instance.spec.time_granularity.base_granularity.to_int() + < agg_time_dimension_instance_for_join.spec.time_granularity.base_granularity.to_int() ): agg_time_dimension_instance_for_join = instance assert ( @@ -996,18 +1004,25 @@ def visit_constrain_time_range_node(self, node: ConstrainTimeRangeNode) -> SqlDa ds >= '2020-01-01' AND ds <= '2020-02-01' instead of this: DATE_TRUNC('month', ds) >= '2020-01-01' AND DATE_TRUNC('month', ds <= '2020-02-01') + + Since time range constraints are always bound by a range of standard date/time values, this conversion + cannot use custom granularities. """ from_data_set: SqlDataSet = node.parent_node.accept(self) from_data_set_alias = self._next_unique_table_alias() time_dimension_instances_for_metric_time = sorted( - from_data_set.metric_time_dimension_instances, - key=lambda x: x.spec.time_granularity.to_int(), + [ + instance + for instance in from_data_set.metric_time_dimension_instances + if not instance.spec.time_granularity.is_custom_granularity + ], + key=lambda x: x.spec.time_granularity.base_granularity.to_int(), ) assert ( len(time_dimension_instances_for_metric_time) > 0 - ), "No metric time dimensions found in the input data set for this node" + ), "No metric time dimensions with standard granularities found in the input data set for this node" time_dimension_instance_for_metric_time = time_dimension_instances_for_metric_time[0] @@ -1064,7 +1079,7 @@ def visit_metric_time_dimension_transform_node(self, node: MetricTimeDimensionTr output_measure_instances.append(measure_instance) # Find time dimension instances that refer to the same dimension as the one specified in the node. - matching_time_dimension_instances = [] + matching_time_dimension_instances: List[TimeDimensionInstance] = [] for time_dimension_instance in input_data_set.instance_set.time_dimension_instances: # The specification for the time dimension to use for aggregation is the local one. if ( @@ -1080,7 +1095,7 @@ def visit_metric_time_dimension_transform_node(self, node: MetricTimeDimensionTr # For those matching time dimension instances, create the analog metric time dimension instances for the output. for matching_time_dimension_instance in matching_time_dimension_instances: metric_time_dimension_spec = DataSet.metric_time_dimension_spec( - time_granularity=matching_time_dimension_instance.spec.time_granularity, + time_granularity=matching_time_dimension_instance.spec.time_granularity.base_granularity, date_part=matching_time_dimension_instance.spec.date_part, ) metric_time_dimension_column_association = self._column_association_resolver.resolve_spec( @@ -1262,8 +1277,12 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet ): agg_time_dimension_instances.append(instance) - # Choose the instance with the smallest granularity available. - agg_time_dimension_instances.sort(key=lambda instance: instance.spec.time_granularity.to_int()) + # Choose the instance with the smallest standard granularity available. + # TODO: [custom granularity] Update to account for custom granularity instances + assert all( + [not instance.spec.time_granularity.is_custom_granularity for instance in agg_time_dimension_instances] + ), "Custom granularities are not yet supported!" + agg_time_dimension_instances.sort(key=lambda instance: instance.spec.time_granularity.base_granularity.to_int()) assert len(agg_time_dimension_instances) > 0, ( "Couldn't find requested agg_time_dimension in parent data set. The dataflow plan may have been " "configured incorrectly." @@ -1352,8 +1371,8 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet # TODO: this will break when we start supporting smaller grain than DAY unless the time spine table is # updated to use the smallest available grain. if ( - time_dimension_spec.time_granularity.to_int() - < original_time_spine_dim_instance.spec.time_granularity.to_int() + time_dimension_spec.time_granularity.base_granularity.to_int() + < original_time_spine_dim_instance.spec.time_granularity.base_granularity.to_int() ): raise RuntimeError( f"Can't join to time spine for a time dimension with a smaller granularity than that of the time " @@ -1362,11 +1381,16 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet ) # Apply grain to time spine select expression, unless grain already matches original time spine column. + should_skip_date_trunc = ( + time_dimension_spec.time_granularity == original_time_spine_dim_instance.spec.time_granularity + or time_dimension_spec.time_granularity.is_custom_granularity + ) select_expr: SqlExpressionNode = ( time_spine_column_select_expr - if time_dimension_spec.time_granularity == original_time_spine_dim_instance.spec.time_granularity + if should_skip_date_trunc else SqlDateTruncExpression.create( - time_granularity=time_dimension_spec.time_granularity, arg=time_spine_column_select_expr + time_granularity=time_dimension_spec.time_granularity.base_granularity, + arg=time_spine_column_select_expr, ) ) # Filter down to one row per granularity period requested in the group by. Any other granularities diff --git a/metricflow/plan_conversion/instance_converters.py b/metricflow/plan_conversion/instance_converters.py index a2c85eaf72..2447bcc56f 100644 --- a/metricflow/plan_conversion/instance_converters.py +++ b/metricflow/plan_conversion/instance_converters.py @@ -339,14 +339,22 @@ def transform(self, instance_set: InstanceSet) -> Optional[ValidityWindowJoinDes spec for spec in specs if spec.element_name == start_dim.dimension_name - and spec.time_granularity == start_dim.time_granularity + # TODO: [custom_granularity] - support custom granularities for SCDs. Note this requires + # addition of SCD support for window sub-selection, similar to what we do for cumulative metrics + # when we group by a different time grain (e.g., select last_value from window, etc.) + and not spec.time_granularity.is_custom_granularity + and spec.time_granularity.base_granularity == start_dim.time_granularity and spec.date_part == start_dim.date_part ] end_specs = [ spec for spec in specs if spec.element_name == end_dim.dimension_name - and spec.time_granularity == end_dim.time_granularity + # TODO: [custom_granularity] - support custom granularities for SCDs. Note this requires + # addition of SCD support for window sub-selection, similar to what we do for cumulative metrics + # when we group by a different time grain (e.g., select last_value from window, etc.) + and not spec.time_granularity.is_custom_granularity + and spec.time_granularity.base_granularity == end_dim.time_granularity and spec.date_part == end_dim.date_part ] linkless_start_specs = {spec.without_entity_links for spec in start_specs} diff --git a/metricflow/plan_conversion/sql_join_builder.py b/metricflow/plan_conversion/sql_join_builder.py index 7bc24b7f11..13954157f7 100644 --- a/metricflow/plan_conversion/sql_join_builder.py +++ b/metricflow/plan_conversion/sql_join_builder.py @@ -240,13 +240,20 @@ def _make_validity_window_on_conditions( We use the instance with the smallest granularity and shortest entity link path, since it will be used in the ON statement for the join against the validity window. + + Note SCD joins are always evaluated against a standard time granularity. Subsequent conversion to + custom granularities should happen after the join. """ if join_description.validity_window is None: return tuple() left_data_set_metric_time_dimension_instances = sorted( - left_data_set.data_set.metric_time_dimension_instances, - key=lambda x: (x.spec.time_granularity.to_int(), len(x.spec.entity_links)), + [ + instance + for instance in left_data_set.data_set.metric_time_dimension_instances + if not instance.spec.time_granularity.is_custom_granularity + ], + key=lambda x: (x.spec.time_granularity.base_granularity.to_int(), len(x.spec.entity_links)), ) assert left_data_set_metric_time_dimension_instances, ( f"Cannot process join to data set with alias {right_data_set.alias} because it has a validity " diff --git a/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py b/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py index 601f6fc436..2fe5a18b56 100644 --- a/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py +++ b/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py @@ -29,6 +29,7 @@ MTD_SPEC_WEEK, ) from metricflow_semantics.test_helpers.snapshot_helpers import assert_plan_snapshot_text_equal +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.dataset.dataset_classes import DataSet @@ -1103,7 +1104,7 @@ def test_min_max_only_time_year( TimeDimensionSpec( element_name="paid_at", entity_links=(EntityReference("booking"),), - time_granularity=TimeGranularity.YEAR, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.YEAR), ), ), min_max_only=True, diff --git a/tests_metricflow/dataflow/builder/test_node_evaluator.py b/tests_metricflow/dataflow/builder/test_node_evaluator.py index 78a7b74bb1..20d932421d 100644 --- a/tests_metricflow/dataflow/builder/test_node_evaluator.py +++ b/tests_metricflow/dataflow/builder/test_node_evaluator.py @@ -13,6 +13,7 @@ from metricflow_semantics.specs.instance_spec import LinkableInstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.sql.sql_join_type import SqlJoinType +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.node_data_set import DataflowPlanNodeOutputDataSetResolver from metricflow.dataflow.builder.node_evaluator import ( @@ -427,12 +428,14 @@ def test_node_evaluator_with_multihop_joined_spec( join_on_partition_time_dimensions=( PartitionTimeDimensionJoinDescription( start_node_time_dimension_spec=TimeDimensionSpec( - element_name="ds_partitioned", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="ds_partitioned", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), node_to_join_time_dimension_spec=TimeDimensionSpec( element_name="ds_partitioned", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), ), diff --git a/tests_metricflow/examples/test_node_sql.py b/tests_metricflow/examples/test_node_sql.py index 4d4f5923bd..fa5793f202 100644 --- a/tests_metricflow/examples/test_node_sql.py +++ b/tests_metricflow/examples/test_node_sql.py @@ -10,6 +10,7 @@ from metricflow_semantics.specs.dunder_column_association_resolver import DunderColumnAssociationResolver from metricflow_semantics.specs.spec_set import InstanceSpecSet from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.node_data_set import DataflowPlanNodeOutputDataSetResolver from metricflow.dataflow.nodes.filter_elements import FilterElementsNode @@ -73,7 +74,11 @@ def test_view_sql_generated_at_a_node( parent_node=metric_time_node, include_specs=InstanceSpecSet( time_dimension_specs=( - TimeDimensionSpec(element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY), + TimeDimensionSpec( + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), + ), ), ), ) diff --git a/tests_metricflow/plan_conversion/dataflow_to_sql/test_conversion_metrics_to_sql.py b/tests_metricflow/plan_conversion/dataflow_to_sql/test_conversion_metrics_to_sql.py index f58ac4c5ee..bfa5cdfb99 100644 --- a/tests_metricflow/plan_conversion/dataflow_to_sql/test_conversion_metrics_to_sql.py +++ b/tests_metricflow/plan_conversion/dataflow_to_sql/test_conversion_metrics_to_sql.py @@ -9,6 +9,7 @@ from metricflow_semantics.specs.query_spec import MetricFlowQuerySpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter @@ -61,7 +62,9 @@ def test_conversion_rate_with_window( entity_links=(EntityReference(element_name="visit"),), ) metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) metric_spec = MetricSpec(element_name="visit_buy_conversion_rate_7days") @@ -149,7 +152,9 @@ def test_conversion_rate_with_constant_properties( entity_links=(EntityReference(element_name="visit"),), ) metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) dataflow_plan = dataflow_plan_builder.build_plan( query_spec=MetricFlowQuerySpec( @@ -179,7 +184,9 @@ def test_conversion_metric_join_to_timespine_and_fill_nulls_with_0( """Test conversion metric that joins to time spine and fills nulls with 0.""" metric_spec = MetricSpec(element_name="visit_buy_conversion_rate_7days_fill_nulls_with_0") metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) dataflow_plan = dataflow_plan_builder.build_plan( query_spec=MetricFlowQuerySpec( diff --git a/tests_metricflow/plan_conversion/instance_converters/test_create_validity_window_join_description.py b/tests_metricflow/plan_conversion/instance_converters/test_create_validity_window_join_description.py index 72cb6ee654..d980230323 100644 --- a/tests_metricflow/plan_conversion/instance_converters/test_create_validity_window_join_description.py +++ b/tests_metricflow/plan_conversion/instance_converters/test_create_validity_window_join_description.py @@ -7,6 +7,7 @@ from metricflow_semantics.instances import InstanceSet from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.nodes.join_to_base import ValidityWindowJoinDescription from metricflow.plan_conversion.instance_converters import CreateValidityWindowJoinDescription @@ -36,16 +37,18 @@ def test_validity_window_conversion( scd_semantic_manifest_lookup: SemanticManifestLookup, ) -> None: """Tests converting an instance set with a single validity window into a ValidityWindowJoinDescription.""" - # The listings semantic model uses a 2-column SCD Type III layout + # The listings semantic model uses a 2-column SCD Type II layout dataset = mf_engine_test_fixture_mapping[SemanticManifestSetup.SCD_MANIFEST].data_set_mapping["listings"] expected_join_description = ValidityWindowJoinDescription( window_start_dimension=TimeDimensionSpec( element_name="window_start", - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), entity_links=(), ), window_end_dimension=TimeDimensionSpec( - element_name="window_end", time_granularity=TimeGranularity.DAY, entity_links=() + element_name="window_end", + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), + entity_links=(), ), ) diff --git a/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py b/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py index 69723a06de..6390b1e8ec 100644 --- a/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py +++ b/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py @@ -182,7 +182,11 @@ def test_filter_with_where_constraint_node( "bookings_source" ] - ds_spec = TimeDimensionSpec(element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY) + ds_spec = TimeDimensionSpec( + element_name="ds", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), + ) filter_node = FilterElementsNode.create( parent_node=source_node, include_specs=InstanceSpecSet(measure_specs=(measure_spec,), time_dimension_specs=(ds_spec,)), @@ -198,7 +202,7 @@ def test_filter_with_where_constraint_node( TimeDimensionSpec( element_name="ds", entity_links=(EntityReference(element_name="booking"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), ), @@ -574,7 +578,9 @@ def test_join_to_time_spine_node_without_offset( entity_spec = LinklessEntitySpec.from_element_name(element_name="listing") metric_input_measure_specs = (MetricInputMeasureSpec(measure_spec=measure_spec),) metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) measure_source_node = mf_engine_test_fixture_mapping[SemanticManifestSetup.SIMPLE_MANIFEST].read_node_mapping[ "bookings_source" @@ -647,7 +653,9 @@ def test_join_to_time_spine_node_with_offset_window( entity_spec = LinklessEntitySpec.from_element_name(element_name="listing") metric_input_measure_specs = (MetricInputMeasureSpec(measure_spec=measure_spec),) metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) measure_source_node = mf_engine_test_fixture_mapping[SemanticManifestSetup.SIMPLE_MANIFEST].read_node_mapping[ "bookings_source" @@ -720,7 +728,9 @@ def test_join_to_time_spine_node_with_offset_to_grain( entity_spec = LinklessEntitySpec.from_element_name(element_name="listing") metric_input_measure_specs = (MetricInputMeasureSpec(measure_spec=measure_spec),) metric_time_spec = TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ) measure_source_node = mf_engine_test_fixture_mapping[SemanticManifestSetup.SIMPLE_MANIFEST].read_node_mapping[ "bookings_source" @@ -969,7 +979,9 @@ def test_semi_additive_join_node_with_queried_group_by( non_additive_dimension_spec = NonAdditiveDimensionSpec(name="ds", window_choice=AggregationType.MIN) time_dimension_spec = TimeDimensionSpec(element_name="ds", entity_links=()) queried_time_dimension_spec = TimeDimensionSpec( - element_name="ds", entity_links=(), time_granularity=TimeGranularity.WEEK + element_name="ds", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.WEEK), ) measure_source_node = mf_engine_test_fixture_mapping[SemanticManifestSetup.SIMPLE_MANIFEST].read_node_mapping[ @@ -1047,7 +1059,11 @@ def test_constrain_time_range_node( ), ), time_dimension_specs=( - TimeDimensionSpec(element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY), + TimeDimensionSpec( + element_name="ds", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), + ), ), ), ) diff --git a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py index f2bd527cc7..b53dfa0f4c 100644 --- a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py +++ b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py @@ -25,6 +25,7 @@ MTD_SPEC_WEEK, MTD_SPEC_YEAR, ) +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter @@ -49,7 +50,7 @@ def test_cumulative_metric( TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), ) @@ -86,7 +87,7 @@ def test_cumulative_metric_with_time_constraint( TimeDimensionSpec( element_name="metric_time", entity_links=(), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), time_range_constraint=TimeRangeConstraint( @@ -183,7 +184,7 @@ def test_cumulative_metric_no_window( TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), ) @@ -242,7 +243,7 @@ def test_cumulative_metric_grain_to_date( TimeDimensionSpec( element_name="ds", entity_links=(), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), ) @@ -328,12 +329,12 @@ def test_cumulative_metric_with_multiple_agg_time_dimensions( TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("revenue_instance"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("revenue_instance"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), ) @@ -390,7 +391,7 @@ def test_cumulative_metric_with_agg_time_and_metric_time( TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("revenue_instance"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), ) @@ -500,7 +501,7 @@ def test_window_metric_with_non_default_grains( TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("booking"),), - time_granularity=TimeGranularity.MONTH, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MONTH), ), ), ) @@ -534,12 +535,12 @@ def test_grain_to_date_metric_with_non_default_grains( TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("revenue_instance"),), - time_granularity=TimeGranularity.QUARTER, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.QUARTER), ), TimeDimensionSpec( element_name="ds", entity_links=(EntityReference("revenue_instance"),), - time_granularity=TimeGranularity.YEAR, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.YEAR), ), ), ) diff --git a/tests_metricflow/query_rendering/test_granularity_date_part_rendering.py b/tests_metricflow/query_rendering/test_granularity_date_part_rendering.py index dc003a7564..c369bb0cd5 100644 --- a/tests_metricflow/query_rendering/test_granularity_date_part_rendering.py +++ b/tests_metricflow/query_rendering/test_granularity_date_part_rendering.py @@ -18,6 +18,7 @@ from metricflow_semantics.specs.query_spec import MetricFlowQuerySpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.dataset.dataset_classes import DataSet @@ -140,7 +141,7 @@ def test_sub_daily_dimension( # noqa: D103 time_dimension_specs=( TimeDimensionSpec( element_name="bio_added_ts", - time_granularity=TimeGranularity.SECOND, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.SECOND), entity_links=(EntityReference("user"),), ), ), @@ -169,7 +170,7 @@ def test_simple_metric_with_sub_daily_dimension( # noqa: D103 time_dimension_specs=( TimeDimensionSpec( element_name="archived_at", - time_granularity=TimeGranularity.HOUR, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.HOUR), entity_links=(EntityReference("user"),), ), ), @@ -198,7 +199,7 @@ def test_simple_metric_with_joined_sub_daily_dimension( # noqa: D103 time_dimension_specs=( TimeDimensionSpec( element_name="bio_added_ts", - time_granularity=TimeGranularity.MINUTE, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.MINUTE), entity_links=( EntityReference("listing"), EntityReference("user"), diff --git a/tests_metricflow/query_rendering/test_metric_time_without_metrics.py b/tests_metricflow/query_rendering/test_metric_time_without_metrics.py index 0978388681..c9c0a80b4b 100644 --- a/tests_metricflow/query_rendering/test_metric_time_without_metrics.py +++ b/tests_metricflow/query_rendering/test_metric_time_without_metrics.py @@ -12,6 +12,7 @@ from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_DAY +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter @@ -55,7 +56,9 @@ def test_metric_time_quarter_alone( # noqa: D103 query_spec=MetricFlowQuerySpec( time_dimension_specs=( TimeDimensionSpec( - element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.QUARTER + element_name="metric_time", + entity_links=(), + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.QUARTER), ), ), ), diff --git a/tests_metricflow/query_rendering/test_query_rendering.py b/tests_metricflow/query_rendering/test_query_rendering.py index abc1af247c..5eb328606e 100644 --- a/tests_metricflow/query_rendering/test_query_rendering.py +++ b/tests_metricflow/query_rendering/test_query_rendering.py @@ -24,6 +24,7 @@ from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_DAY, MTD_SPEC_WEEK +from metricflow_semantics.time.granularity import ExpandedTimeGranularity from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.dataset.dataset_classes import DataSet @@ -482,7 +483,7 @@ def test_min_max_only_time( TimeDimensionSpec( element_name="paid_at", entity_links=(EntityReference("booking"),), - time_granularity=TimeGranularity.DAY, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.DAY), ), ), min_max_only=True, @@ -512,7 +513,7 @@ def test_min_max_only_time_quarter( TimeDimensionSpec( element_name="paid_at", entity_links=(EntityReference("booking"),), - time_granularity=TimeGranularity.QUARTER, + time_granularity=ExpandedTimeGranularity.from_time_granularity(TimeGranularity.QUARTER), ), ), min_max_only=True, diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 7c2d19392d..017713318e 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -16,8 +16,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day + DATE_TRUNC('day', subq_5.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_5 + GROUP BY + DATE_TRUNC('day', subq_5.ds) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures @@ -124,8 +126,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_18.ds AS metric_time__day + DATE_TRUNC('day', subq_18.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_18 + GROUP BY + DATE_TRUNC('day', subq_18.ds) ) subq_17 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 7f85edf1f7..f0b12c79e8 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -11,9 +11,16 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_26.ds AS metric_time__day + subq_25.metric_time__day AS metric_time__day , subq_24.visits AS visits - FROM ***************************.mf_time_spine subq_26 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_26 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_25 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,14 +39,21 @@ FROM ( metric_time__day ) subq_24 ON - subq_26.ds = subq_24.metric_time__day + subq_25.metric_time__day = subq_24.metric_time__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_39.ds AS metric_time__day + subq_38.metric_time__day AS metric_time__day , subq_37.buys AS buys - FROM ***************************.mf_time_spine subq_39 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_39 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_38 LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -121,7 +135,7 @@ FROM ( metric_time__day ) subq_37 ON - subq_39.ds = subq_37.metric_time__day + subq_38.metric_time__day = subq_37.metric_time__day ) subq_40 ON subq_27.metric_time__day = subq_40.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml index 18a94623a9..0d47695b76 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml @@ -63,12 +63,11 @@ - - - - - + + + + @@ -501,12 +500,11 @@ - - - - - + + + + diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql index 417d11e301..0b8e02798e 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 @@ -78,12 +78,12 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('week', subq_3.ds) , DATE_TRUNC('quarter', subq_3.ds) ) subq_2 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..818f885944 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 @@ -28,12 +28,12 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week , DATE_TRUNC('quarter', ds) AS metric_time__quarter FROM ***************************.mf_time_spine subq_12 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('week', ds) , DATE_TRUNC('quarter', ds) ) subq_11 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql index 8af29da836..3210cbab63 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -59,9 +59,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_4.ds AS metric_time__day + DATE_TRUNC('day', subq_4.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_4 WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' + GROUP BY + DATE_TRUNC('day', subq_4.ds) ) subq_3 INNER JOIN ( -- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00] diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql index 0c658869b2..8a451ec0e0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -9,9 +9,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' + GROUP BY + DATE_TRUNC('day', ds) ) subq_12 INNER JOIN ( -- Read Elements From Semantic Model 'revenue' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 78a6550fbd..a922cde77f 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -58,11 +58,11 @@ FROM ( -- Time Spine SELECT DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month - , subq_3.ds AS metric_time__day + , DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 GROUP BY DATE_TRUNC('month', subq_3.ds) - , subq_3.ds + , DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index eaaba26ba2..ff9f0ec081 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -10,11 +10,11 @@ FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS revenue_instance__ds__month - , ds AS metric_time__day + , DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_10 GROUP BY DATE_TRUNC('month', ds) - , ds + , DATE_TRUNC('day', ds) ) subq_9 INNER JOIN ***************************.fct_revenue revenue_src_28000 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql index 126f491236..128234fe67 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql @@ -54,8 +54,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS revenue_instance__ds__day + DATE_TRUNC('day', subq_3.ds) AS revenue_instance__ds__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql index 4719e4a5ff..33c877d730 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql @@ -3,16 +3,23 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ds AS revenue_instance__ds__day + subq_9.revenue_instance__ds__day AS revenue_instance__ds__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ***************************.mf_time_spine subq_10 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS revenue_instance__ds__day + FROM ***************************.mf_time_spine subq_10 + GROUP BY + DATE_TRUNC('day', ds) +) subq_9 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.revenue_instance__ds__day - INTERVAL 2 month ) GROUP BY - subq_10.ds + subq_9.revenue_instance__ds__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 08079e14cc..fc99664e45 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -57,11 +57,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS revenue_instance__ds__day + DATE_TRUNC('day', subq_3.ds) AS revenue_instance__ds__day , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index df79dc0757..755077d986 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -9,11 +9,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS revenue_instance__ds__day + DATE_TRUNC('day', ds) AS revenue_instance__ds__day , DATE_TRUNC('month', ds) AS revenue_instance__ds__month FROM ***************************.mf_time_spine subq_10 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) ) subq_9 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index ec77b12959..fbe6dfeec0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -57,11 +57,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 5a4fb59200..56c4a2ff92 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -9,11 +9,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month FROM ***************************.mf_time_spine subq_10 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) ) subq_9 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql index 1a771a2886..54885dab43 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql @@ -121,8 +121,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql index e62e61f0c3..915fef9b09 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql @@ -8,16 +8,23 @@ FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day + subq_10.metric_time__day AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_11 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_10 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_11.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_10.metric_time__day ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_11.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_10.metric_time__day - INTERVAL 2 day ) ) subq_13 WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql index a83909ad88..550db4382e 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 @@ -71,11 +71,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..88c6b1d789 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 @@ -23,11 +23,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week FROM ***************************.mf_time_spine subq_12 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('week', ds) ) subq_11 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql index f381377090..b00b549e45 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql @@ -59,9 +59,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_4.ds AS metric_time__day + DATE_TRUNC('day', subq_4.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_4 WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' + GROUP BY + DATE_TRUNC('day', subq_4.ds) ) subq_3 INNER JOIN ( -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00] diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql index f6f5b25650..783e5a5bde 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -9,9 +9,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' + GROUP BY + DATE_TRUNC('day', ds) ) subq_12 INNER JOIN ( -- Read Elements From Semantic Model 'revenue' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index 95969c9da1..ab485c5ebd 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 @@ -72,11 +72,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 363d16e9bd..79caf8b507 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 @@ -24,11 +24,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week FROM ***************************.mf_time_spine subq_13 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('week', ds) ) subq_12 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql index aab94914af..21bf873dcf 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -71,11 +71,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('month', subq_3.ds) AS metric_time__month FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('month', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..f85735034b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -23,11 +23,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month FROM ***************************.mf_time_spine subq_12 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) ) subq_11 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 92e8a38290..650e22974b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -80,12 +80,12 @@ FROM ( SELECT DATE_TRUNC('quarter', subq_3.ds) AS revenue_instance__ds__quarter , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year - , subq_3.ds AS metric_time__day + , DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 GROUP BY DATE_TRUNC('quarter', subq_3.ds) , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds + , DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..b087e7f9fb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -30,12 +30,12 @@ FROM ( SELECT DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter , DATE_TRUNC('year', ds) AS revenue_instance__ds__year - , ds AS metric_time__day + , DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_12 GROUP BY DATE_TRUNC('quarter', ds) , DATE_TRUNC('year', ds) - , ds + , DATE_TRUNC('day', ds) ) subq_11 INNER JOIN ***************************.fct_revenue revenue_src_28000 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql index cf6722d1ca..f8e70dec9f 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 @@ -67,11 +67,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('year', subq_3.ds) AS metric_time__year FROM ***************************.mf_time_spine subq_3 GROUP BY - subq_3.ds + DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('year', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql index 03e4ba7fc4..ca757d2892 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 @@ -19,11 +19,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('year', ds) AS metric_time__year FROM ***************************.mf_time_spine subq_12 GROUP BY - ds + DATE_TRUNC('day', ds) , DATE_TRUNC('year', ds) ) subq_11 INNER JOIN diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql index 113268bbb1..6ccea053e3 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql @@ -32,8 +32,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures @@ -154,12 +156,12 @@ FROM ( -- Time Spine SELECT DATE_TRUNC('month', subq_3.ds) AS booking__ds__month - , subq_3.ds AS metric_time__day + , DATE_TRUNC('day', subq_3.ds) AS metric_time__day , DATE_TRUNC('week', subq_3.ds) AS metric_time__week FROM ***************************.mf_time_spine subq_3 GROUP BY DATE_TRUNC('month', subq_3.ds) - , subq_3.ds + , DATE_TRUNC('day', subq_3.ds) , DATE_TRUNC('week', subq_3.ds) ) subq_2 INNER JOIN ( diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql index d2e2b91c1d..87500b7805 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -19,11 +19,18 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_20.ds AS metric_time__day - , DATE_TRUNC('week', subq_20.ds) AS metric_time__week + subq_19.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_19.metric_time__day) AS metric_time__week , subq_18.booking__ds__month AS booking__ds__month , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_20 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_19 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] @@ -37,12 +44,12 @@ FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS booking__ds__month - , ds AS metric_time__day + , DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week FROM ***************************.mf_time_spine subq_15 GROUP BY DATE_TRUNC('month', ds) - , ds + , DATE_TRUNC('day', ds) , DATE_TRUNC('week', ds) ) subq_14 INNER JOIN @@ -59,7 +66,7 @@ FROM ( , subq_14.metric_time__week ) subq_18 ON - subq_20.ds = subq_18.metric_time__day + subq_19.metric_time__day = subq_18.metric_time__day ) subq_21 ) subq_23 GROUP BY diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_common_semantic_model__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_common_semantic_model__dfp_0.xml index 3e238cc281..a858d37305 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_common_semantic_model__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_common_semantic_model__dfp_0.xml @@ -22,7 +22,11 @@ - + + + + + @@ -37,7 +41,11 @@ - + + + + + @@ -89,7 +97,11 @@ - + + + + + @@ -105,7 +117,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_no_window_or_grain_with_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_no_window_or_grain_with_metric_time__dfp_0.xml index b525e0d0fe..14b91fd6fb 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_no_window_or_grain_with_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_no_window_or_grain_with_metric_time__dfp_0.xml @@ -13,13 +13,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_non_default_grain__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_non_default_grain__dfp_0.xml index dbe0527c9a..d7a5165024 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_non_default_grain__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_non_default_grain__dfp_0.xml @@ -6,8 +6,18 @@ - - + + + + + + + + + + + + @@ -20,17 +30,31 @@ - - + + + + + + + + + + - - - - - + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_window__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_window__dfp_0.xml index 1f0d6c8ddd..4f0bf5034f 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_window__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_cumulative_metric_with_window__dfp_0.xml @@ -13,13 +13,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_cumulative_metric_with_non_default_grain__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_cumulative_metric_with_non_default_grain__dfp_0.xml index 2efe5aa275..b9bf963f55 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_cumulative_metric_with_non_default_grain__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_cumulative_metric_with_non_default_grain__dfp_0.xml @@ -10,8 +10,18 @@ - - + + + + + + + + + + + + @@ -24,17 +34,31 @@ - - + + + + + + + + + + - - - - - + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml index e60cd4ce07..60b0f12c7a 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml @@ -20,7 +20,11 @@ - + + + + + @@ -47,13 +51,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml index 5146d02f68..7c268973d6 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml @@ -22,13 +22,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml index bc9790a704..8b323050cd 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml @@ -22,13 +22,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml index 5055b1e115..ebbab1e3c5 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml @@ -22,13 +22,22 @@ - + + + + + - - + + + + + + + @@ -37,8 +46,13 @@ - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml index 18a280f887..b83cb223ff 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml @@ -7,7 +7,11 @@ - + + + + + @@ -27,7 +31,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml index c869b82bf5..17eeb4bf57 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml @@ -16,8 +16,13 @@ - - + + + + + + + @@ -30,7 +35,11 @@ - + + + + + @@ -58,8 +67,13 @@ - - + + + + + + + @@ -72,13 +86,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml index c2a5359ee6..50316718a8 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -81,7 +84,10 @@ - + + + + @@ -90,8 +96,13 @@ - - + + + + + + + @@ -136,7 +147,10 @@ - + + + + @@ -145,8 +159,11 @@ - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml index f1f04adbbe..d0523cc91e 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml @@ -9,8 +9,13 @@ - - + + + + + + + @@ -23,7 +28,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_non_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_non_metric_time__dfp_0.xml index 727ccd4696..88a6c47515 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_non_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_non_metric_time__dfp_0.xml @@ -13,12 +13,12 @@ - - - - - - + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_limit_rows_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_limit_rows_plan__dfp_0.xml index c265115098..6f085318f4 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_limit_rows_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_limit_rows_plan__dfp_0.xml @@ -17,7 +17,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml index 513d59195e..ef4a3fc46d 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_plan__dfp_0.xml @@ -73,7 +73,11 @@ - + + + + + @@ -138,8 +142,11 @@ - - + + + + + @@ -156,8 +163,14 @@ - - + + + + + + + + @@ -260,7 +273,11 @@ - + + + + + @@ -325,8 +342,11 @@ - - + + + + + @@ -342,8 +362,14 @@ - - + + + + + + + + @@ -393,7 +419,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml index b9d5262d37..fce10fcf79 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml @@ -64,7 +64,11 @@ - + + + + + @@ -119,8 +123,11 @@ - - + + + + + @@ -148,7 +155,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_only__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_only__dfp_0.xml index 0d0b8c95fe..36266f92e9 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_only__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_only__dfp_0.xml @@ -5,7 +5,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_quarter__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_quarter__dfp_0.xml index a7ec17768a..e58a87fe41 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_quarter__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_quarter__dfp_0.xml @@ -5,7 +5,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_with_other_dimensions__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_with_other_dimensions__dfp_0.xml index c98504cdc4..98dbbba896 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_with_other_dimensions__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_time_with_other_dimensions__dfp_0.xml @@ -11,8 +11,16 @@ - - + + + + + + + + + + @@ -33,8 +41,16 @@ - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time__dfp_0.xml index 527a7bd36b..ec0e09f3f2 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time__dfp_0.xml @@ -8,7 +8,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time_week__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time_week__dfp_0.xml index 61fd7ad0b7..dda234e942 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time_week__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_metric_time_week__dfp_0.xml @@ -8,7 +8,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time__dfp_0.xml index 16301f285f..26dded2b57 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time__dfp_0.xml @@ -8,12 +8,12 @@ - - - - - - + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time_year__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time_year__dfp_0.xml index 7f4200ead4..473648c86c 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time_year__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_min_max_only_time_year__dfp_0.xml @@ -8,12 +8,12 @@ - - - - - - + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml index 337915e429..7e620b5c4b 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml @@ -26,7 +26,11 @@ - + + + + + @@ -41,8 +45,11 @@ - - + + + + + @@ -94,7 +101,11 @@ - + + + + + @@ -109,8 +120,11 @@ - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multihop_join_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multihop_join_plan__dfp_0.xml index 25d62e8faa..9fe8220797 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multihop_join_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multihop_join_plan__dfp_0.xml @@ -34,11 +34,17 @@ - + + + + - + + + + @@ -47,7 +53,11 @@ - + + + + + @@ -71,7 +81,11 @@ - + + + + + @@ -86,11 +100,17 @@ - + + + + - + + + + @@ -160,170 +180,218 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multiple_metrics_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multiple_metrics_plan__dfp_0.xml index fca709df16..68223678f4 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multiple_metrics_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multiple_metrics_plan__dfp_0.xml @@ -21,7 +21,11 @@ - + + + + + @@ -53,7 +57,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml index 323e1990f6..338fa413db 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml @@ -9,8 +9,13 @@ - - + + + + + + + @@ -39,13 +44,22 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml index ddd17b1584..95f2c0484c 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -79,7 +82,10 @@ - + + + + @@ -95,7 +101,11 @@ - + + + + + @@ -129,7 +139,10 @@ - + + + + @@ -139,15 +152,30 @@ - - - + + + + + + + + + + - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml index 2a578f548b..452e48a547 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -82,7 +85,10 @@ - + + + + @@ -97,7 +103,11 @@ - + + + + + @@ -131,7 +141,10 @@ - + + + + @@ -142,16 +155,33 @@ - - - - + + + + + + + + + + + + + - - + + + + + + + + + + @@ -208,7 +238,10 @@ - + + + + @@ -222,7 +255,11 @@ - + + + + + @@ -256,7 +293,10 @@ - + + + + @@ -266,10 +306,19 @@ - - - - + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_order_by_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_order_by_plan__dfp_0.xml index 8b94cd3388..d0ec1221b3 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_order_by_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_order_by_plan__dfp_0.xml @@ -5,11 +5,14 @@ - - - - - + + + + + + + + @@ -23,7 +26,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml index 79a3605555..dab3c934ed 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_single_semantic_model_ratio_metrics_plan__dfp_0.xml @@ -26,7 +26,11 @@ - + + + + + @@ -41,8 +45,11 @@ - - + + + + + @@ -94,7 +101,11 @@ - + + + + + @@ -109,8 +120,11 @@ - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_where_constrained_plan_time_dimension__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_where_constrained_plan_time_dimension__dfp_0.xml index 03ea5bd452..bea1ca13e9 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_where_constrained_plan_time_dimension__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_where_constrained_plan_time_dimension__dfp_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -89,7 +92,10 @@ - + + + + @@ -104,7 +110,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml index 7d725d6e47..ee960d5dfc 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml @@ -5,8 +5,13 @@ - - + + + + + + + @@ -27,7 +32,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml index ad88440282..bbc356942c 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml @@ -5,8 +5,13 @@ - - + + + + + + + @@ -27,7 +32,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_without_offset__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_without_offset__plan0.xml index 104727cda1..ff11742636 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_without_offset__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/DataflowPlan/test_join_to_time_spine_node_without_offset__plan0.xml @@ -5,8 +5,13 @@ - - + + + + + + + @@ -27,7 +32,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql index d1eb9e6cdf..a233b840e1 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql index 6054b232dc..619fe8dda3 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', ds) ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql index 6556fc936f..b615e5b538 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql index 836bd707a7..e7f2f038dc 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', ds) ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql index 2c925cc021..2cde263f64 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql index e4f47734b0..5526f612ef 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql @@ -6,9 +6,11 @@ SELECT FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' + GROUP BY + DATE_TRUNC('day', ds) ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml index 6af78e498c..b1ce2b5da2 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml @@ -18,9 +18,9 @@ - - + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml index 6af78e498c..b1ce2b5da2 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml @@ -18,9 +18,9 @@ - - + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml index 6af78e498c..b1ce2b5da2 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml @@ -18,9 +18,9 @@ - - + + diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index bdc24e7203..be335ae479 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -126,9 +126,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 WHERE subq_6.ds BETWEEN '2019-12-19' AND '2020-01-02' + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 INNER JOIN ( -- Join Self Over Time Range @@ -234,8 +236,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index 7f6df5eeba..38f81978d1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -14,23 +14,32 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_18 WHERE ds BETWEEN '2019-12-19' AND '2020-01-02' + GROUP BY + DATE_TRUNC('day', ds) ) subq_17 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_15.ds AS metric_time__day + subq_14.metric_time__day AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_14 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.metric_time__day - INTERVAL 2 day ) ) subq_16 ON diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index a9d3e6d977..c5e4c8f4f2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index aa15f38c06..8606ce0b97 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day + subq_21.metric_time__day AS metric_time__day , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + DATE_TRUNC('month', subq_21.metric_time__day) = subq_20.metric_time__day GROUP BY - subq_22.ds + subq_21.metric_time__day ) subq_26 ON subq_18.metric_time__day = subq_26.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index eb72ea9213..b5b64053b3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 808ffc27a1..ec1a53ac20 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('week', subq_22.ds) AS metric_time__week + DATE_TRUNC('week', subq_21.metric_time__day) AS metric_time__week , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,10 +51,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day - WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + DATE_TRUNC('month', subq_21.metric_time__day) = subq_20.metric_time__day + WHERE DATE_TRUNC('week', subq_21.metric_time__day) = subq_21.metric_time__day GROUP BY - DATE_TRUNC('week', subq_22.ds) + DATE_TRUNC('week', subq_21.metric_time__day) ) subq_26 ON subq_18.metric_time__week = subq_26.metric_time__week diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index daf3021522..7c5a4a9bda 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql index 2995f673a7..d9613e88e1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day + subq_21.metric_time__day AS metric_time__day , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_21.metric_time__day - INTERVAL 14 day = subq_20.metric_time__day GROUP BY - subq_22.ds + subq_21.metric_time__day ) subq_26 ON subq_18.metric_time__day = subq_26.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 6f85a9e19f..ddc4bc3be7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 851b05e511..3b50fe841d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('quarter', subq_22.ds) AS metric_time__quarter + DATE_TRUNC('quarter', subq_21.metric_time__day) AS metric_time__quarter , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_21.metric_time__day - INTERVAL 14 day = subq_20.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_22.ds) + DATE_TRUNC('quarter', subq_21.metric_time__day) ) subq_26 ON subq_18.metric_time__quarter = subq_26.metric_time__quarter diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 1d66e64171..0fbedba875 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -127,8 +127,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' @@ -452,8 +454,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_11.ds AS metric_time__day + DATE_TRUNC('day', subq_11.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', subq_11.ds) ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 0c68fbd1a2..2ff3178dc8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -14,9 +14,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_20.ds AS metric_time__day + subq_19.metric_time__day AS metric_time__day , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_20 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -26,9 +33,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_18 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + DATE_TRUNC('month', subq_19.metric_time__day) = subq_18.metric_time__day GROUP BY - subq_20.ds + subq_19.metric_time__day ) subq_24 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -36,9 +43,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day + subq_27.metric_time__day AS metric_time__day , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_28 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_27 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -48,9 +62,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_26 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + subq_27.metric_time__day - INTERVAL 1 month = subq_26.metric_time__day GROUP BY - subq_28.ds + subq_27.metric_time__day ) subq_32 ON subq_24.metric_time__day = subq_32.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 7871e327c5..69ab1b290a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -127,8 +127,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' @@ -453,8 +455,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_11.ds AS metric_time__day + DATE_TRUNC('day', subq_11.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', subq_11.ds) ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 76ccda3ffe..2a2111ccd6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -14,9 +14,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_20.ds) AS metric_time__year + DATE_TRUNC('year', subq_19.metric_time__day) AS metric_time__year , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_20 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -26,10 +33,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_18 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', subq_19.metric_time__day) = subq_18.metric_time__day + WHERE DATE_TRUNC('year', subq_19.metric_time__day) = subq_19.metric_time__day GROUP BY - DATE_TRUNC('year', subq_20.ds) + DATE_TRUNC('year', subq_19.metric_time__day) ) subq_24 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -37,9 +44,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_28.ds) AS metric_time__year + DATE_TRUNC('year', subq_27.metric_time__day) AS metric_time__year , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_28 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_27 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -49,9 +63,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_26 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + subq_27.metric_time__day - INTERVAL 1 month = subq_26.metric_time__day GROUP BY - DATE_TRUNC('year', subq_28.ds) + DATE_TRUNC('year', subq_27.metric_time__day) ) subq_32 ON subq_24.metric_time__year = subq_32.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 03120b4353..8c3fb1f516 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -354,8 +354,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_9.ds AS metric_time__day + DATE_TRUNC('day', subq_9.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_9 + GROUP BY + DATE_TRUNC('day', subq_9.ds) ) subq_8 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 86908af230..673a79aeca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -39,9 +39,16 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_25.ds AS metric_time__day + subq_24.metric_time__day AS metric_time__day , subq_23.bookings AS bookings - FROM ***************************.mf_time_spine subq_25 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_25 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_24 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -51,7 +58,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_23 ON - subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day + subq_24.metric_time__day - INTERVAL 14 day = subq_23.metric_time__day ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index 8d51b413df..42e1b1db4f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -121,8 +121,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 INNER JOIN ( -- Join Self Over Time Range @@ -228,8 +230,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql index d55d82114b..60d6af8539 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -8,26 +8,40 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day + subq_16.metric_time__day AS metric_time__day , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_17 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_17 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_16 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_14.ds AS metric_time__day + subq_13.metric_time__day AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_14 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_14 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_13 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.metric_time__day ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.metric_time__day - INTERVAL 2 day ) ) subq_15 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + subq_16.metric_time__day - INTERVAL 2 day = subq_15.metric_time__day GROUP BY - subq_17.ds + subq_16.metric_time__day ) subq_21 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index d04a641f27..452789be4b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -127,8 +127,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS booking__ds__day + DATE_TRUNC('day', subq_3.ds) AS booking__ds__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index ee97120d59..3b838b25f5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql @@ -14,15 +14,22 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS booking__ds__day + subq_16.booking__ds__day AS booking__ds__day , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS booking__ds__day + FROM ***************************.mf_time_spine subq_17 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + subq_16.booking__ds__day - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds + subq_16.booking__ds__day ) subq_21 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 380c658a9e..ac8bdfe5e3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -121,8 +121,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index cfa50604ff..7c03aa4eef 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -8,9 +8,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day + subq_10.metric_time__day AS metric_time__day , SUM(subq_9.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_11 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -20,7 +27,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_9 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + subq_10.metric_time__day - INTERVAL 5 day = subq_9.metric_time__day GROUP BY - subq_11.ds + subq_10.metric_time__day ) subq_15 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index aa0490fb4b..206545af73 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -22,8 +22,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day + DATE_TRUNC('day', subq_10.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_10 + GROUP BY + DATE_TRUNC('day', subq_10.ds) ) subq_9 INNER JOIN ( -- Compute Metrics via Expressions @@ -153,8 +155,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 94a07bed7d..fd333525e0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -11,10 +11,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + subq_23.metric_time__day AS metric_time__day , subq_22.booking__is_instant AS booking__is_instant , subq_22.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_24 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_24 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_23 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -27,10 +34,17 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day + subq_16.metric_time__day AS metric_time__day , subq_15.booking__is_instant AS booking__is_instant , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine subq_17 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_17 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -41,14 +55,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day + subq_16.metric_time__day - INTERVAL 5 day = subq_15.metric_time__day GROUP BY - subq_17.ds + subq_16.metric_time__day , subq_15.booking__is_instant ) subq_21 ) subq_22 ON - subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day + subq_23.metric_time__day - INTERVAL 2 day = subq_22.metric_time__day ) subq_25 WHERE booking__is_instant ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 5ac836a079..34d9a5b8a6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -16,8 +16,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day + DATE_TRUNC('day', subq_7.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_7 + GROUP BY + DATE_TRUNC('day', subq_7.ds) ) subq_6 INNER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index b10c0ed06c..9683308f28 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql @@ -11,9 +11,16 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day + subq_22.metric_time__day AS metric_time__day , subq_21.booking_fees_start_of_month AS booking_fees_start_of_month - FROM ***************************.mf_time_spine subq_23 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_23 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_22 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -34,7 +41,7 @@ FROM ( ) subq_20 ) subq_21 ON - DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day + DATE_TRUNC('month', subq_22.metric_time__day) = subq_21.metric_time__day ) subq_24 FULL OUTER JOIN ( -- Compute Metrics via Expressions diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index 6c69cb987f..73a0702e91 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day + DATE_TRUNC('day', subq_10.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_10 + GROUP BY + DATE_TRUNC('day', subq_10.ds) ) subq_9 INNER JOIN ( -- Compute Metrics via Expressions @@ -137,8 +139,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql index fd6f165b33..6de53928d5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql @@ -5,9 +5,16 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day + subq_21.metric_time__day AS metric_time__day , subq_20.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -19,9 +26,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_15.ds AS metric_time__day + subq_14.metric_time__day AS metric_time__day , SUM(subq_13.bookings) AS bookings - FROM ***************************.mf_time_spine subq_15 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_14 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -31,11 +45,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_13 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + subq_14.metric_time__day - INTERVAL 5 day = subq_13.metric_time__day GROUP BY - subq_15.ds + subq_14.metric_time__day ) subq_19 ) subq_20 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day + subq_21.metric_time__day - INTERVAL 2 day = subq_20.metric_time__day ) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index c0b1ea0b18..1123a3151a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -10,9 +10,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day + DATE_TRUNC('day', subq_10.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_10 WHERE subq_10.ds BETWEEN '2020-01-12' AND '2020-01-13' + GROUP BY + DATE_TRUNC('day', subq_10.ds) ) subq_9 INNER JOIN ( -- Compute Metrics via Expressions @@ -138,8 +140,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql index df8acf3b4d..83f1012aa3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -10,9 +10,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_22 WHERE ds BETWEEN '2020-01-12' AND '2020-01-13' + GROUP BY + DATE_TRUNC('day', ds) ) subq_21 INNER JOIN ( -- Compute Metrics via Expressions @@ -25,9 +27,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_15.ds AS metric_time__day + subq_14.metric_time__day AS metric_time__day , SUM(subq_13.bookings) AS bookings - FROM ***************************.mf_time_spine subq_15 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_14 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -37,9 +46,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_13 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + subq_14.metric_time__day - INTERVAL 5 day = subq_13.metric_time__day GROUP BY - subq_15.ds + subq_14.metric_time__day ) subq_19 ) subq_20 ON diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index a532fe0b30..b7fc33be7f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -15,8 +15,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day + DATE_TRUNC('day', subq_10.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_10 + GROUP BY + DATE_TRUNC('day', subq_10.ds) ) subq_9 INNER JOIN ( -- Compute Metrics via Expressions @@ -142,8 +144,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 767f991871..b2a2bf5e91 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -10,9 +10,16 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day + subq_22.metric_time__day AS metric_time__day , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_23 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_22 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day + subq_15.metric_time__day AS metric_time__day , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_16 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_15 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,13 +50,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_14 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + subq_15.metric_time__day - INTERVAL 5 day = subq_14.metric_time__day GROUP BY - subq_16.ds + subq_15.metric_time__day ) subq_20 ) subq_21 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day + subq_22.metric_time__day - INTERVAL 2 day = subq_21.metric_time__day ) subq_24 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index c633e0a0db..ddbc576dcd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -133,8 +133,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index bfd3b8fbce..3b3ab93020 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -14,10 +14,17 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] SELECT - subq_13.ds AS metric_time__day - , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + subq_12.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_12.metric_time__day) AS metric_time__month , subq_11.bookings AS bookings - FROM ***************************.mf_time_spine subq_13 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_12 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -27,8 +34,8 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_11 ON - DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day - WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + DATE_TRUNC('month', subq_12.metric_time__day) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_12.metric_time__day) = subq_12.metric_time__day ) subq_15 WHERE metric_time__day = '2020-01-01' GROUP BY diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 8a62bf7c11..237e290cca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -129,8 +129,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 76767e46c6..e8bea713fe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -10,11 +10,18 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , DATE_TRUNC('month', subq_11.ds) AS metric_time__month - , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year , SUM(subq_9.bookings) AS bookings_start_of_month - FROM ***************************.mf_time_spine subq_11 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -24,9 +31,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_9 ON - DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day GROUP BY - subq_11.ds - , DATE_TRUNC('month', subq_11.ds) - , DATE_TRUNC('year', subq_11.ds) + subq_10.metric_time__day + , DATE_TRUNC('month', subq_10.metric_time__day) + , DATE_TRUNC('year', subq_10.metric_time__day) ) subq_15 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index 8734e9a26a..abfd20d6db 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS booking__ds__day + DATE_TRUNC('day', subq_8.ds) AS booking__ds__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 87a86d9826..817001782a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day + subq_21.booking__ds__day AS booking__ds__day , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS booking__ds__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.booking__ds__day + DATE_TRUNC('month', subq_21.booking__ds__day) = subq_20.booking__ds__day GROUP BY - subq_22.ds + subq_21.booking__ds__day ) subq_26 ON subq_18.booking__ds__day = subq_26.booking__ds__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index d3a6d4aadf..f8f6e4b38c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -139,8 +139,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 0def7f4cf6..5db64b4257 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -20,14 +20,21 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] SELECT - subq_21.ds AS metric_time__day - , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + subq_20.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_20.metric_time__day) AS metric_time__month , bookings_source_src_28000.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_21 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_21 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_20 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_21.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + subq_20.metric_time__day - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) ) subq_23 WHERE metric_time__day = '2020-01-01' GROUP BY diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql index 92f1870c03..46661ff815 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -137,8 +137,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 7a9df9d3d5..da165fbc00 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -18,19 +18,26 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , DATE_TRUNC('month', subq_17.ds) AS metric_time__month - , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + subq_16.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_16.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_16.metric_time__day) AS metric_time__year , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_17 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + subq_16.metric_time__day - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - , DATE_TRUNC('month', subq_17.ds) - , DATE_TRUNC('year', subq_17.ds) + subq_16.metric_time__day + , DATE_TRUNC('month', subq_16.metric_time__day) + , DATE_TRUNC('year', subq_16.metric_time__day) ) subq_21 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index 10520fd03d..8fd757a0d4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS booking__ds__day + DATE_TRUNC('day', subq_8.ds) AS booking__ds__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql index cacae6cc3a..488cad92cb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day + subq_21.booking__ds__day AS booking__ds__day , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS booking__ds__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.booking__ds__day + subq_21.booking__ds__day - INTERVAL 14 day = subq_20.booking__ds__day GROUP BY - subq_22.ds + subq_21.booking__ds__day ) subq_26 ON subq_18.booking__ds__day = subq_26.booking__ds__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index a3c227a694..23de754b25 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -121,9 +121,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 WHERE subq_3.ds BETWEEN '2019-12-19' AND '2020-01-02' + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index d1f30b244b..8ec7f42a06 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -13,9 +13,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_11 WHERE ds BETWEEN '2019-12-19' AND '2020-01-02' + GROUP BY + DATE_TRUNC('day', ds) ) subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql index e30f09d486..747d2e55e5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures @@ -127,8 +129,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql index 80c8cdd0e9..1837786a95 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql @@ -5,28 +5,42 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_18.ds AS metric_time__day + subq_17.metric_time__day AS metric_time__day , subq_16.bookers AS bookers - FROM ***************************.mf_time_spine subq_18 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_18 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_17 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] -- Aggregate Measures SELECT - subq_13.ds AS metric_time__day + subq_12.metric_time__day AS metric_time__day , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_13 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_13 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_12 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_12.metric_time__day ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_12.metric_time__day - INTERVAL 2 day ) GROUP BY - subq_13.ds + subq_12.metric_time__day ) subq_16 ON - subq_18.ds = subq_16.metric_time__day + subq_17.metric_time__day = subq_16.metric_time__day ) subq_19 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index eb0612129b..b7dfc3ce25 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -21,8 +21,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day + DATE_TRUNC('day', subq_5.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_5 + GROUP BY + DATE_TRUNC('day', subq_5.ds) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures @@ -356,8 +358,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_11.ds AS metric_time__day + DATE_TRUNC('day', subq_11.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_11 + GROUP BY + DATE_TRUNC('day', subq_11.ds) ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 918daa9a18..6ee7d6d22f 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -16,9 +16,16 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day + subq_21.metric_time__day AS metric_time__day , subq_20.bookings AS bookings - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -37,7 +44,7 @@ FROM ( metric_time__day ) subq_20 ON - subq_22.ds = subq_20.metric_time__day + subq_21.metric_time__day = subq_20.metric_time__day ) subq_23 ) subq_24 FULL OUTER JOIN ( @@ -46,9 +53,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day + subq_27.metric_time__day AS metric_time__day , SUM(subq_26.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_28 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_28 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_27 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -58,9 +72,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_26 ON - subq_28.ds - INTERVAL 14 day = subq_26.metric_time__day + subq_27.metric_time__day - INTERVAL 14 day = subq_26.metric_time__day GROUP BY - subq_28.ds + subq_27.metric_time__day ) subq_32 ON subq_24.metric_time__day = subq_32.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql index 007e38a03c..1eb1ea3c16 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql @@ -15,9 +15,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 WHERE subq_8.ds BETWEEN '2020-01-03' AND '2020-01-05' + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql index ae0e42a39e..9a2899f346 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql @@ -11,9 +11,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_19 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' + GROUP BY + DATE_TRUNC('day', ds) ) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql index bd106944b5..0c4601f84c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day + DATE_TRUNC('day', subq_5.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_5 + GROUP BY + DATE_TRUNC('day', subq_5.ds) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 591b4614fd..48714d9c84 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql @@ -5,9 +5,16 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day + subq_11.metric_time__day AS metric_time__day , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_12 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -26,5 +33,5 @@ FROM ( metric_time__day ) subq_10 ON - subq_12.ds = subq_10.metric_time__day + subq_11.metric_time__day = subq_10.metric_time__day ) subq_13 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index a0db6aa138..c44a413d65 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -342,8 +342,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day + DATE_TRUNC('day', subq_8.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_8 + GROUP BY + DATE_TRUNC('day', subq_8.ds) ) subq_7 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql index 9ab2ad55e6..ed58225e6e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql @@ -32,9 +32,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - EXTRACT(isodow FROM subq_22.ds) AS metric_time__extract_dow + EXTRACT(isodow FROM subq_21.metric_time__day) AS metric_time__extract_dow , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_21 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -44,9 +51,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_20 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_21.metric_time__day - INTERVAL 14 day = subq_20.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_22.ds) + EXTRACT(isodow FROM subq_21.metric_time__day) ) subq_26 ON subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql index 1a252f2ebe..d10f754f77 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql @@ -208,8 +208,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ts AS metric_time__hour + DATE_TRUNC('hour', subq_3.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_3 + GROUP BY + DATE_TRUNC('hour', subq_3.ts) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'archived_at' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql index fe834fa9e6..6dc56e8981 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql @@ -3,9 +3,16 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ts AS metric_time__hour + subq_9.metric_time__hour AS metric_time__hour , SUM(subq_8.archived_users) AS subdaily_cumulative_grain_to_date_metric -FROM ***************************.mf_time_spine_hour subq_10 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_10 + GROUP BY + DATE_TRUNC('hour', ts) +) subq_9 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -16,9 +23,9 @@ INNER JOIN ( ) subq_8 ON ( - subq_8.metric_time__hour <= subq_10.ts + subq_8.metric_time__hour <= subq_9.metric_time__hour ) AND ( - subq_8.metric_time__hour >= DATE_TRUNC('hour', subq_10.ts) + subq_8.metric_time__hour >= DATE_TRUNC('hour', subq_9.metric_time__hour) ) GROUP BY - subq_10.ts + subq_9.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql index a18b954931..b96a4084ad 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql @@ -208,8 +208,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ts AS metric_time__hour + DATE_TRUNC('hour', subq_3.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_3 + GROUP BY + DATE_TRUNC('hour', subq_3.ts) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'archived_at' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql index f031751858..47ba71b714 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql @@ -3,9 +3,16 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ts AS metric_time__hour + subq_9.metric_time__hour AS metric_time__hour , SUM(subq_8.archived_users) AS subdaily_cumulative_window_metric -FROM ***************************.mf_time_spine_hour subq_10 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_10 + GROUP BY + DATE_TRUNC('hour', ts) +) subq_9 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -16,9 +23,9 @@ INNER JOIN ( ) subq_8 ON ( - subq_8.metric_time__hour <= subq_10.ts + subq_8.metric_time__hour <= subq_9.metric_time__hour ) AND ( - subq_8.metric_time__hour > subq_10.ts - INTERVAL 3 hour + subq_8.metric_time__hour > subq_9.metric_time__hour - INTERVAL 3 hour ) GROUP BY - subq_10.ts + subq_9.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index fe488e80ff..ba6f2d7ccd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ts AS metric_time__hour + DATE_TRUNC('hour', subq_5.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_5 + GROUP BY + DATE_TRUNC('hour', subq_5.ts) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 44763c6b6e..cd1bc0eaea 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -1,9 +1,16 @@ -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour + subq_11.metric_time__hour AS metric_time__hour , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_12 + GROUP BY + DATE_TRUNC('hour', ts) +) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -22,4 +29,4 @@ LEFT OUTER JOIN ( metric_time__hour ) subq_10 ON - subq_12.ts = subq_10.metric_time__hour + subq_11.metric_time__hour = subq_10.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql index fe488e80ff..ba6f2d7ccd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ts AS metric_time__hour + DATE_TRUNC('hour', subq_5.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_5 + GROUP BY + DATE_TRUNC('hour', subq_5.ts) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 44763c6b6e..cd1bc0eaea 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -1,9 +1,16 @@ -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour + subq_11.metric_time__hour AS metric_time__hour , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_12 + GROUP BY + DATE_TRUNC('hour', ts) +) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -22,4 +29,4 @@ LEFT OUTER JOIN ( metric_time__hour ) subq_10 ON - subq_12.ts = subq_10.metric_time__hour + subq_11.metric_time__hour = subq_10.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql index d30be670b4..a0f6d69c3a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql @@ -213,8 +213,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ts AS metric_time__hour + DATE_TRUNC('hour', subq_3.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_3 + GROUP BY + DATE_TRUNC('hour', subq_3.ts) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'archived_at' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 2679104380..4ed2614091 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql @@ -8,9 +8,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour + subq_10.metric_time__hour AS metric_time__hour , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_11 + GROUP BY + DATE_TRUNC('hour', ts) + ) subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -20,7 +27,7 @@ FROM ( FROM ***************************.dim_users users_ds_source_src_28000 ) subq_9 ON - DATE_TRUNC('hour', subq_11.ts) = subq_9.metric_time__hour + DATE_TRUNC('hour', subq_10.metric_time__hour) = subq_9.metric_time__hour GROUP BY - subq_11.ts + subq_10.metric_time__hour ) subq_15 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql index 9a1d976fcd..a2cdddc258 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql @@ -213,8 +213,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ts AS metric_time__hour + DATE_TRUNC('hour', subq_3.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_3 + GROUP BY + DATE_TRUNC('hour', subq_3.ts) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'archived_at' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql index 66fbdfb392..eab99e0ba4 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql @@ -8,9 +8,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour + subq_10.metric_time__hour AS metric_time__hour , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_11 + GROUP BY + DATE_TRUNC('hour', ts) + ) subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -20,7 +27,7 @@ FROM ( FROM ***************************.dim_users users_ds_source_src_28000 ) subq_9 ON - subq_11.ts - INTERVAL 1 hour = subq_9.metric_time__hour + subq_10.metric_time__hour - INTERVAL 1 hour = subq_9.metric_time__hour GROUP BY - subq_11.ts + subq_10.metric_time__hour ) subq_15 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql index f1543cd157..7bceed2c3f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql @@ -15,9 +15,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ts AS metric_time__hour + DATE_TRUNC('hour', subq_6.ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_6 WHERE subq_6.ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + GROUP BY + DATE_TRUNC('hour', subq_6.ts) ) subq_5 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index 7fef407456..640fbba6f2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -7,9 +7,11 @@ SELECT FROM ( -- Time Spine SELECT - ts AS metric_time__hour + DATE_TRUNC('hour', ts) AS metric_time__hour FROM ***************************.mf_time_spine_hour subq_15 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + GROUP BY + DATE_TRUNC('hour', ts) ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml index 508028c4e9..7ad32f714a 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml @@ -65,7 +65,11 @@ - + + + + + @@ -125,7 +129,11 @@ - + + + + + @@ -147,8 +155,14 @@ - - + + + + + + + + @@ -191,7 +205,11 @@ - + + + + + @@ -212,16 +230,26 @@ - + + + + + - - - - + + + + + + + + + + @@ -241,9 +269,22 @@ - - - + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml index 2341f512f2..d35f059305 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml @@ -65,7 +65,11 @@ - + + + + + @@ -83,7 +87,11 @@ - + + + + + @@ -105,8 +113,11 @@ - - + + + + + @@ -191,7 +202,11 @@ - + + + + + @@ -212,16 +227,26 @@ - + + + + + - - - - + + + + + + + + + + @@ -241,9 +266,22 @@ - - - + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfp_0.xml index 40a2704f90..c31c343de1 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfp_0.xml @@ -61,7 +61,11 @@ - + + + + + @@ -121,7 +125,11 @@ - + + + + + @@ -143,15 +151,26 @@ - - + + + + + - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfpo_0.xml index d556224391..42a4942691 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_cumulative_metric_predicate_pushdown__dfpo_0.xml @@ -61,7 +61,11 @@ - + + + + + @@ -79,7 +83,11 @@ - + + + + + @@ -101,14 +109,23 @@ - + + + + + - - + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml index fa96c0fc07..6ddc35d3b2 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml @@ -102,8 +102,13 @@ - - + + + + + + + @@ -122,7 +127,11 @@ - + + + + + @@ -182,8 +191,14 @@ - - + + + + + + + + @@ -205,8 +220,14 @@ - - + + + + + + + + @@ -298,8 +319,13 @@ - - + + + + + + + @@ -318,7 +344,11 @@ - + + + + + @@ -378,8 +408,14 @@ - - + + + + + + + + @@ -401,20 +437,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml index 2abd1529b6..29aa9318d9 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml @@ -102,8 +102,13 @@ - - + + + + + + + @@ -122,7 +127,11 @@ - + + + + + @@ -140,8 +149,11 @@ - - + + + + + @@ -163,8 +175,14 @@ - - + + + + + + + + @@ -300,8 +318,13 @@ - - + + + + + + + @@ -320,7 +343,11 @@ - + + + + + @@ -380,8 +407,14 @@ - - + + + + + + + + @@ -403,20 +436,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml index 306327193a..3da28f6b88 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml @@ -145,8 +145,13 @@ - - + + + + + + + @@ -213,8 +218,14 @@ - - + + + + + + + + @@ -236,8 +247,14 @@ - - + + + + + + + + @@ -372,8 +389,13 @@ - - + + + + + + + @@ -440,8 +462,14 @@ - - + + + + + + + + @@ -463,20 +491,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml index e26e0929bf..95f2d06915 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml @@ -145,8 +145,13 @@ - - + + + + + + + @@ -171,8 +176,11 @@ - - + + + + + @@ -194,8 +202,14 @@ - - + + + + + + + + @@ -374,8 +388,13 @@ - - + + + + + + + @@ -442,8 +461,14 @@ - - + + + + + + + + @@ -465,20 +490,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml index 14cfac8d48..c0e8831b43 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml @@ -112,7 +112,11 @@ - + + + + + @@ -172,8 +176,11 @@ - - + + + + + @@ -195,8 +202,14 @@ - - + + + + + + + + @@ -297,7 +310,11 @@ - + + + + + @@ -357,8 +374,11 @@ - - + + + + + @@ -380,20 +400,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml index 81006e956b..2fe9b2919b 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml @@ -112,7 +112,11 @@ - + + + + + @@ -130,7 +134,11 @@ - + + + + + @@ -152,8 +160,14 @@ - - + + + + + + + + @@ -295,7 +309,11 @@ - + + + + + @@ -355,8 +373,11 @@ - - + + + + + @@ -378,20 +399,29 @@ - - + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfp_0.xml index cd713d5d7c..a96be3d209 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfp_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -89,7 +92,10 @@ - + + + + @@ -104,7 +110,11 @@ - + + + + + @@ -119,8 +129,11 @@ - - + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfpo_0.xml index 5de7f20594..e1a03ea3a2 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_simple_join_metric_time_pushdown_with_two_targets__dfpo_0.xml @@ -37,7 +37,10 @@ - + + + + @@ -89,7 +92,10 @@ - + + + + @@ -104,7 +110,11 @@ - + + + + + @@ -119,8 +129,11 @@ - - + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql index 48a9f31b84..9ab0d49c48 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql @@ -148,8 +148,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_3.ds AS metric_time__day + DATE_TRUNC('day', subq_3.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('day', subq_3.ds) ) subq_2 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql index 8511580120..14b8e1e480 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql @@ -11,10 +11,17 @@ FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_18.ds AS metric_time__day + subq_17.metric_time__day AS metric_time__day , subq_16.listing AS listing , subq_16.bookers AS bookers - FROM ***************************.mf_time_spine subq_18 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_18 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_17 INNER JOIN ( -- Constrain Output with WHERE SELECT @@ -35,9 +42,9 @@ FROM ( ) subq_16 ON ( - subq_16.metric_time__day <= subq_18.ds + subq_16.metric_time__day <= subq_17.metric_time__day ) AND ( - subq_16.metric_time__day > subq_18.ds - INTERVAL 2 day + subq_16.metric_time__day > subq_17.metric_time__day - INTERVAL 2 day ) ) subq_20 LEFT OUTER JOIN diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 620302ced3..675ef4dc52 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -25,8 +25,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_12.ds AS metric_time__day + DATE_TRUNC('day', subq_12.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_12 + GROUP BY + DATE_TRUNC('day', subq_12.ds) ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures @@ -433,8 +435,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_30.ds AS metric_time__day + DATE_TRUNC('day', subq_30.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_30 + GROUP BY + DATE_TRUNC('day', subq_30.ds) ) subq_29 LEFT OUTER JOIN ( -- Aggregate Measures @@ -581,8 +585,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_18.ds AS metric_time__day + DATE_TRUNC('day', subq_18.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_18 + GROUP BY + DATE_TRUNC('day', subq_18.ds) ) subq_17 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index d968e659d1..53083d3937 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -19,10 +19,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_46.ds AS metric_time__day + subq_45.metric_time__day AS metric_time__day , subq_44.listing__country_latest AS listing__country_latest , subq_44.bookings AS bookings - FROM ***************************.mf_time_spine subq_46 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_46 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_45 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] @@ -60,7 +67,7 @@ FROM ( , listings_latest_src_28000.country ) subq_44 ON - subq_46.ds = subq_44.metric_time__day + subq_45.metric_time__day = subq_44.metric_time__day ) subq_47 ) subq_48 FULL OUTER JOIN ( @@ -72,10 +79,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_64.ds AS metric_time__day + subq_63.metric_time__day AS metric_time__day , subq_62.listing__country_latest AS listing__country_latest , subq_62.bookings AS bookings - FROM ***************************.mf_time_spine subq_64 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_64 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_63 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -96,11 +110,18 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_52.ds AS metric_time__day + subq_51.metric_time__day AS metric_time__day , subq_50.listing AS listing , subq_50.booking__is_instant AS booking__is_instant , subq_50.bookings AS bookings - FROM ***************************.mf_time_spine subq_52 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_52 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_51 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -112,7 +133,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_50 ON - subq_52.ds - INTERVAL 14 day = subq_50.metric_time__day + subq_51.metric_time__day - INTERVAL 14 day = subq_50.metric_time__day ) subq_54 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 @@ -125,7 +146,7 @@ FROM ( , listing__country_latest ) subq_62 ON - subq_64.ds = subq_62.metric_time__day + subq_63.metric_time__day = subq_62.metric_time__day ) subq_65 ) subq_66 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql index 2bbf738849..9d83d09f9b 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql @@ -554,8 +554,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_15.ds AS metric_time__day + DATE_TRUNC('day', subq_15.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', subq_15.ds) ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 57d56fe5d4..a582e24dbb 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql @@ -68,11 +68,18 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_43.ds AS metric_time__day + subq_42.metric_time__day AS metric_time__day , subq_41.listing AS listing , subq_41.booking__is_instant AS booking__is_instant , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine subq_43 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_43 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_42 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -84,7 +91,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_41 ON - subq_43.ds - INTERVAL 14 day = subq_41.metric_time__day + subq_42.metric_time__day - INTERVAL 14 day = subq_41.metric_time__day ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 00f2cc5ddb..ee0d39ba56 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -18,8 +18,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 8892599ad9..c97b53e629 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql @@ -7,10 +7,17 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day + subq_14.metric_time__day AS metric_time__day , subq_13.booking__is_instant AS booking__is_instant , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_14 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -34,6 +41,6 @@ FROM ( , booking__is_instant ) subq_13 ON - subq_15.ds = subq_13.metric_time__day + subq_14.metric_time__day = subq_13.metric_time__day ) subq_16 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfp_0.xml index 3e238cc281..a858d37305 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfp_0.xml @@ -22,7 +22,11 @@ - + + + + + @@ -37,7 +41,11 @@ - + + + + + @@ -89,7 +97,11 @@ - + + + + + @@ -105,7 +117,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfpo_0.xml index 27aa822fc6..8eb95c772c 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_1_semantic_model__dfpo_0.xml @@ -22,7 +22,11 @@ - + + + + + @@ -39,7 +43,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfp_0.xml index b5ca1e4635..08f4c08b7c 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfp_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -42,7 +46,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfpo_0.xml index ff9319fc5f..3a71422521 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_metrics_from_2_semantic_models__dfpo_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -42,7 +46,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml index d77af7fd2e..9eb673964a 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfp_0.xml @@ -23,7 +23,11 @@ - + + + + + @@ -49,7 +53,11 @@ - + + + + + @@ -84,7 +92,11 @@ - + + + + + @@ -110,7 +122,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfpo_0.xml index 7f00282d0b..6bbfdedda3 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_2_ratio_metrics_from_1_semantic_model__dfpo_0.xml @@ -23,7 +23,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfp_0.xml index 3ae6ae714d..361d5828ef 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfp_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -42,7 +46,11 @@ - + + + + + @@ -68,7 +76,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfpo_0.xml index 6ef679c21b..f1e91edd7e 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_3_metrics_from_2_semantic_models__dfpo_0.xml @@ -18,7 +18,11 @@ - + + + + + @@ -44,7 +48,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml index 7ed3cde452..23dcf84f95 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -42,7 +46,11 @@ - + + + + + @@ -96,7 +104,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml index 24a165f0d0..950ea86ea8 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -42,7 +46,11 @@ - + + + + + @@ -96,7 +104,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml index 59767f93a5..072ac54f7f 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfp_0.xml @@ -20,7 +20,11 @@ - + + + + + @@ -46,7 +50,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfpo_0.xml index f8f0df21da..7f26acf6e3 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric__dfpo_0.xml @@ -19,7 +19,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml index 31b945fa6f..83aeaf2599 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfp_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -49,7 +53,11 @@ - + + + + + @@ -75,7 +83,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfpo_0.xml index 6f7c7310c5..50934e5b2c 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_derived_metric_with_non_derived_metric__dfpo_0.xml @@ -16,7 +16,11 @@ - + + + + + @@ -49,7 +53,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfp_0.xml index 172b4c617d..5486091770 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfp_0.xml @@ -20,7 +20,11 @@ - + + + + + @@ -51,7 +55,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfpo_0.xml index be6e77b322..fe785f7e22 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_duplicate_measures__dfpo_0.xml @@ -18,7 +18,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml index 6f1a895dcf..28dd28d2b6 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfp_0.xml @@ -27,8 +27,11 @@ - - + + + + + @@ -54,8 +57,11 @@ - - + + + + + @@ -83,7 +89,11 @@ - + + + + + @@ -109,7 +119,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml index af89a195c5..17a1508a38 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_nested_derived_metric__dfpo_0.xml @@ -27,7 +27,11 @@ - + + + + + @@ -57,7 +61,11 @@ - + + + + + diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index a7fd42dafc..dd8433e339 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -15,9 +15,11 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 WHERE subq_6.ds BETWEEN '2020-01-03' AND '2020-01-05' + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index fb7e2c593f..6819a9d433 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql @@ -11,9 +11,11 @@ FROM ( FROM ( -- Time Spine SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day FROM ***************************.mf_time_spine subq_15 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' + GROUP BY + DATE_TRUNC('day', ds) ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql index 0ea077947e..ede1b4d1c9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day + DATE_TRUNC('day', subq_5.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_5 + GROUP BY + DATE_TRUNC('day', subq_5.ds) ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql index 03e7c6a8a1..4c2b5b9b75 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql @@ -1,9 +1,16 @@ -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day + subq_11.metric_time__day AS metric_time__day , subq_10.bookings AS bookings_join_to_time_spine -FROM ***************************.mf_time_spine subq_12 +FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_12 + GROUP BY + DATE_TRUNC('day', ds) +) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -22,4 +29,4 @@ LEFT OUTER JOIN ( metric_time__day ) subq_10 ON - subq_12.ds = subq_10.metric_time__day + subq_11.metric_time__day = subq_10.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql index a39da38b06..3e8412226d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -10,8 +10,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day + DATE_TRUNC('day', subq_7.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_7 + GROUP BY + DATE_TRUNC('day', subq_7.ds) ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 9a4f540d4c..b4a7b8308d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql @@ -5,9 +5,16 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day + subq_15.metric_time__day AS metric_time__day , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_16 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_15 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -30,5 +37,5 @@ FROM ( metric_time__day ) subq_14 ON - subq_16.ds = subq_14.metric_time__day + subq_15.metric_time__day = subq_14.metric_time__day ) subq_17 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index ed0bc69197..411a5f04b2 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -18,8 +18,10 @@ FROM ( FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day + DATE_TRUNC('day', subq_6.ds) AS metric_time__day FROM ***************************.mf_time_spine subq_6 + GROUP BY + DATE_TRUNC('day', subq_6.ds) ) subq_5 LEFT OUTER JOIN ( -- Aggregate Measures diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 19f81cdd9b..8c2109274c 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql @@ -12,10 +12,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day + subq_14.metric_time__day AS metric_time__day , subq_13.booking__is_instant AS booking__is_instant , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + FROM ( + -- Time Spine + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_14 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -39,7 +46,7 @@ FROM ( , booking__is_instant ) subq_13 ON - subq_15.ds = subq_13.metric_time__day + subq_14.metric_time__day = subq_13.metric_time__day ) subq_16 WHERE booking__is_instant ) subq_17