From 4d145e86f9193b578d6f1f8f045e8cd043f8d47c Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 14:54:12 -0800 Subject: [PATCH] WIP - evaluating snapshots --- .../specs/time_dimension_spec.py | 6 +- .../dataflow/builder/dataflow_plan_builder.py | 138 +- metricflow/dataflow/builder/source_node.py | 1 + .../dataflow/nodes/join_to_time_spine.py | 32 +- metricflow/dataset/sql_dataset.py | 16 + metricflow/plan_conversion/dataflow_to_sql.py | 156 ++- ...timespine_and_fill_nulls_with_0__plan0.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.xml | 582 +++++---- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 50 +- ...ouped_by_custom_grain__plan0_optimized.sql | 36 +- ..._metric_with_custom_granularity__plan0.sql | 64 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 264 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._derived_metric_offset_to_grain__dfp_0.xml | 7 +- ...st_derived_metric_offset_window__dfp_0.xml | 7 +- ..._metric_offset_with_granularity__dfp_0.xml | 7 +- ...erived_offset_cumulative_metric__dfp_0.xml | 7 +- ...in_to_time_spine_derived_metric__dfp_0.xml | 17 +- ...join_to_time_spine_with_filters__dfp_0.xml | 13 +- ..._to_time_spine_with_metric_time__dfp_0.xml | 5 + ...erived_metric_with_outer_offset__dfp_0.xml | 12 +- ...ry_have_different_granularities__dfp_0.xml | 7 +- ...ry_have_different_granularities__dfp_0.xml | 9 +- ...set_metric_with_time_constraint__plan0.sql | 258 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 60 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 68 +- ..._with_offset_to_grain__plan0_optimized.sql | 30 +- ...offset_to_grain_and_granularity__plan0.sql | 76 +- ...grain_and_granularity__plan0_optimized.sql | 32 +- ...rived_metric_with_offset_window__plan0.sql | 68 +- ...ic_with_offset_window__plan0_optimized.sql | 30 +- ...h_offset_window_and_granularity__plan0.sql | 74 +- ...indow_and_granularity__plan0_optimized.sql | 30 +- ...fset_window_and_offset_to_grain__plan0.sql | 520 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 40 +- ...offset_to_grain_and_granularity__plan0.sql | 532 ++++---- ...grain_and_granularity__plan0_optimized.sql | 42 +- ...h_offset_window_and_time_filter__plan0.sql | 266 ++-- ...indow_and_time_filter__plan0_optimized.sql | 30 +- ...erived_offset_cumulative_metric__plan0.sql | 58 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 290 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 58 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 126 +- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 274 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../DuckDB/test_nested_offsets__plan0.sql | 100 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 108 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 106 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 264 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 90 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 68 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 30 +- ...ry_have_different_granularities__plan0.sql | 692 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 350 +++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 68 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 30 +- ...set_metric_with_time_constraint__plan0.sql | 258 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- .../test_cumulative_fill_nulls__plan0.sql | 40 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 506 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 42 +- ...ine_with_filter_not_in_group_by__plan0.sql | 54 +- ...ilter_not_in_group_by__plan0_optimized.sql | 26 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 28 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 26 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 26 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 34 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 40 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 42 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- ...ides_metric_default_granularity__plan0.sql | 40 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 40 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 58 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 58 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 56 +- ...onstraint_with_metric__plan0_optimized.sql | 23 +- ...spine_metric_predicate_pushdown__dfp_0.xml | 26 +- ...pine_metric_predicate_pushdown__dfpo_0.xml | 34 +- ...ost_agg_join_predicate_pushdown__dfp_0.xml | 26 +- ...st_agg_join_predicate_pushdown__dfpo_0.xml | 34 +- ...ffset_metric_predicate_pushdown__dfp_0.xml | 16 +- ...fset_metric_predicate_pushdown__dfpo_0.xml | 24 +- ...spine_metric_predicate_pushdown__plan0.sql | 1110 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 88 +- ..._metric_with_query_time_filters__plan0.sql | 630 +++++----- ...th_query_time_filters__plan0_optimized.sql | 60 +- ...ine_pushdown_filter_application__plan0.sql | 50 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 22 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 25 +- .../test_simple_join_to_time_spine__plan0.sql | 40 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 40 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 50 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- 127 files changed, 6744 insertions(+), 4900 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py b/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py index 6ccd569661..fd47c80a69 100644 --- a/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py +++ b/metricflow-semantics/metricflow_semantics/specs/time_dimension_spec.py @@ -246,14 +246,14 @@ def with_entity_prefix(self, entity_prefix: EntityReference) -> TimeDimensionSpe ) @staticmethod - def with_base_grains(time_dimension_specs: Sequence[TimeDimensionSpec]) -> List[TimeDimensionSpec]: + def with_base_grains(time_dimension_specs: Sequence[TimeDimensionSpec]) -> Tuple[TimeDimensionSpec, ...]: """Return the list of time dimension specs, replacing any custom grains with base grains. Dedupes new specs, but preserves the initial order. """ - base_grain_specs: List[TimeDimensionSpec] = [] + base_grain_specs: Tuple[TimeDimensionSpec, ...] = () for spec in time_dimension_specs: base_grain_spec = spec.with_base_grain() if base_grain_spec not in base_grain_specs: - base_grain_specs.append(base_grain_spec) + base_grain_specs += (base_grain_spec,) return base_grain_specs diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 79e1a81a3a..3cd6da1b7a 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -1,5 +1,6 @@ from __future__ import annotations +import copy import logging import time from typing import Dict, FrozenSet, List, Optional, Sequence, Set, Tuple, Union @@ -87,9 +88,12 @@ from metricflow.dataflow.nodes.join_to_base import JoinDescription, JoinOnEntitiesNode from metricflow.dataflow.nodes.join_to_custom_granularity import JoinToCustomGranularityNode from metricflow.dataflow.nodes.join_to_time_spine import JoinToTimeSpineNode +from metricflow.dataflow.nodes.metric_time_transform import MetricTimeDimensionTransformNode from metricflow.dataflow.nodes.min_max import MinMaxNode from metricflow.dataflow.nodes.order_by_limit import OrderByLimitNode +from metricflow.dataflow.nodes.read_sql_source import ReadSqlSourceNode from metricflow.dataflow.nodes.semi_additive_join import SemiAdditiveJoinNode +from metricflow.dataflow.nodes.transform_time_dimensions import TransformTimeDimensionsNode from metricflow.dataflow.nodes.where_filter import WhereConstraintNode from metricflow.dataflow.nodes.window_reaggregation_node import WindowReaggregationNode from metricflow.dataflow.nodes.write_to_data_table import WriteToResultDataTableNode @@ -642,13 +646,16 @@ def _build_derived_metric_output_node( # For ratio / derived metrics with time offset, apply offset join here. Constraints will be applied after the offset # to avoid filtering out values that will be changed. - if metric_spec.has_time_offset: - queried_agg_time_dimension_specs = queried_linkable_specs.included_agg_time_dimension_specs_for_metric( - metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup - ) + queried_agg_time_dimension_specs = queried_linkable_specs.included_agg_time_dimension_specs_for_metric( + metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup + ) + if metric_spec.has_time_offset and queried_agg_time_dimension_specs: + time_spine_node = self._build_time_spine_node(queried_agg_time_dimension_specs) output_node = JoinToTimeSpineNode.create( parent_node=output_node, + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=queried_agg_time_dimension_specs, + join_on_time_dimension_spec=self._sort_by_base_granularity(queried_agg_time_dimension_specs)[0], offset_window=metric_spec.offset_window, offset_to_grain=metric_spec.offset_to_grain, join_type=SqlJoinType.INNER, @@ -677,7 +684,7 @@ def _build_derived_metric_output_node( def _get_base_agg_time_dimensions( self, queried_linkable_specs: LinkableSpecSet, measure_reference: MeasureReference - ) -> Sequence[TimeDimensionSpec]: + ) -> Tuple[TimeDimensionSpec, ...]: """Get queried agg_time_dimensios with their base grains, deduped. Custom grains are joined right before measure aggregation and after all other pre-aggregation joins, @@ -1037,8 +1044,7 @@ def _find_source_node_recipe_non_cached( ) # If metric_time is requested without metrics, choose appropriate time spine node to select those values from. if linkable_specs_to_satisfy.metric_time_specs: - time_spine_source = self._choose_time_spine_source(linkable_specs_to_satisfy.metric_time_specs) - time_spine_node = self._source_node_set.time_spine_metric_time_nodes[time_spine_source.base_granularity] + time_spine_node = self._choose_time_spine_metric_time_node(linkable_specs_to_satisfy.metric_time_specs) candidate_nodes_for_right_side_of_join += [time_spine_node] candidate_nodes_for_left_side_of_join += [time_spine_node] default_join_type = SqlJoinType.FULL_OUTER @@ -1591,17 +1597,17 @@ def _build_aggregated_measure_from_measure_source_node( f"Unable to join all items in request. Measure: {measure_spec.element_name}; Specs to join: {required_linkable_specs}" ) - base_agg_time_dimension_specs = self._get_base_agg_time_dimensions( + base_queried_agg_time_dimension_specs = self._get_base_agg_time_dimensions( queried_linkable_specs=queried_linkable_specs, measure_reference=measure_spec.reference ) # If a cumulative metric is queried with metric_time / agg_time_dimension, join over time range. # Otherwise, the measure will be aggregated over all time. unaggregated_measure_node: DataflowPlanNode = measure_recipe.source_node - if cumulative and base_agg_time_dimension_specs: + if cumulative and base_queried_agg_time_dimension_specs: unaggregated_measure_node = JoinOverTimeRangeNode.create( parent_node=unaggregated_measure_node, - queried_agg_time_dimension_specs=tuple(base_agg_time_dimension_specs), + queried_agg_time_dimension_specs=tuple(base_queried_agg_time_dimension_specs), window=cumulative_window, grain_to_date=cumulative_grain_to_date, # Note: we use the original constraint here because the JoinOverTimeRangeNode will eventually get @@ -1614,16 +1620,32 @@ def _build_aggregated_measure_from_measure_source_node( ) # If querying an offset metric, join to time spine before aggregation. - if before_aggregation_time_spine_join_description is not None: + if before_aggregation_time_spine_join_description and base_queried_agg_time_dimension_specs: + # TODO: move all of this to a helper function assert before_aggregation_time_spine_join_description.join_type is SqlJoinType.INNER, ( f"Expected {SqlJoinType.INNER} for joining to time spine before aggregation. Remove this if there's a " f"new use case." ) - # This also uses the original time range constraint due to the application of the time window intervals - # in join rendering + + # Determine the spec to join on. Defaults to metric_time if it is included in the request, else agg_time. + # Will use the smallest available grain for the meeasure. + required_time_spine_specs = base_queried_agg_time_dimension_specs + join_spec_grain = ExpandedTimeGranularity.from_time_granularity(measure_properties.agg_time_dimension_grain) + join_on_time_dimension_spec = DataSet.metric_time_dimension_spec(time_granularity=join_spec_grain) + if not LinkableSpecSet(time_dimension_specs=required_time_spine_specs).contains_metric_time: + sample_agg_time_dimension_spec = required_time_spine_specs[0] + join_on_time_dimension_spec = sample_agg_time_dimension_spec.with_grain_and_date_part( + time_granularity=join_spec_grain, date_part=None + ) + required_time_spine_specs += (join_on_time_dimension_spec,) + time_spine_node = self._build_time_spine_node(required_time_spine_specs) + + # Join time spine to source node. unaggregated_measure_node = JoinToTimeSpineNode.create( parent_node=unaggregated_measure_node, - requested_agg_time_dimension_specs=base_agg_time_dimension_specs, + time_spine_node=time_spine_node, + requested_agg_time_dimension_specs=base_queried_agg_time_dimension_specs, + join_on_time_dimension_spec=join_on_time_dimension_spec, offset_window=before_aggregation_time_spine_join_description.offset_window, offset_to_grain=before_aggregation_time_spine_join_description.offset_to_grain, join_type=before_aggregation_time_spine_join_description.join_type, @@ -1662,11 +1684,17 @@ def _build_aggregated_measure_from_measure_source_node( after_aggregation_time_spine_join_description = ( metric_input_measure_spec.after_aggregation_time_spine_join_description ) - if after_aggregation_time_spine_join_description is not None: + queried_agg_time_dimension_specs = queried_linkable_specs.included_agg_time_dimension_specs_for_measure( + measure_reference=measure_spec.reference, semantic_model_lookup=self._semantic_model_lookup + ) + if after_aggregation_time_spine_join_description and queried_agg_time_dimension_specs: + # TODO: move all of this to a helper function assert after_aggregation_time_spine_join_description.join_type is SqlJoinType.LEFT_OUTER, ( f"Expected {SqlJoinType.LEFT_OUTER} for joining to time spine after aggregation. Remove this if " f"there's a new use case." ) + time_spine_required_specs = copy.deepcopy(queried_agg_time_dimension_specs) + # Find filters that contain only metric_time or agg_time_dimension. They will be applied to the time spine table. agg_time_only_filters: List[WhereFilterSpec] = [] non_agg_time_filters: List[WhereFilterSpec] = [] @@ -1676,27 +1704,23 @@ def _build_aggregated_measure_from_measure_source_node( ) if set(included_agg_time_specs) == set(filter_spec.linkable_spec_set.as_tuple): agg_time_only_filters.append(filter_spec) - if filter_spec.linkable_spec_set.time_dimension_specs_with_custom_grain: - raise ValueError( - "Using custom granularity in filters for `join_to_timespine` metrics is not yet fully supported. " - "This feature is coming soon!" - ) + for agg_time_spec in included_agg_time_specs: + if agg_time_spec not in time_spine_required_specs: + time_spine_required_specs.append(agg_time_spec) else: non_agg_time_filters.append(filter_spec) - # TODO: split this node into TimeSpineSourceNode and JoinToTimeSpineNode - then can use standard nodes here - # like JoinToCustomGranularityNode, WhereConstraintNode, etc. - queried_agg_time_dimension_specs = queried_linkable_specs.included_agg_time_dimension_specs_for_measure( - measure_reference=measure_spec.reference, semantic_model_lookup=self._semantic_model_lookup + time_spine_node = self._build_time_spine_node( + queried_time_spine_specs=queried_agg_time_dimension_specs, + time_range_constraint=predicate_pushdown_state.time_range_constraint, + where_filter_specs=agg_time_only_filters, ) output_node: DataflowPlanNode = JoinToTimeSpineNode.create( parent_node=aggregate_measures_node, + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=queried_agg_time_dimension_specs, + join_on_time_dimension_spec=self._sort_by_base_granularity(queried_agg_time_dimension_specs)[0], join_type=after_aggregation_time_spine_join_description.join_type, - time_range_constraint=predicate_pushdown_state.time_range_constraint, - offset_window=after_aggregation_time_spine_join_description.offset_window, - offset_to_grain=after_aggregation_time_spine_join_description.offset_to_grain, - time_spine_filters=agg_time_only_filters, ) # Since new rows might have been added due to time spine join, re-apply constraints here. Only re-apply filters @@ -1812,3 +1836,61 @@ def _choose_time_spine_source(self, required_time_spine_specs: Sequence[TimeDime required_time_spine_specs=required_time_spine_specs, time_spine_sources=self._source_node_builder.time_spine_sources, ) + + def _choose_time_spine_metric_time_node( + self, required_time_spine_specs: Sequence[TimeDimensionSpec] + ) -> MetricTimeDimensionTransformNode: + """Return the MetricTimeDimensionTransform time spine node needed to satisfy the specs.""" + time_spine_source = self._choose_time_spine_source(required_time_spine_specs) + return self._source_node_set.time_spine_metric_time_nodes[time_spine_source.base_granularity] + + def _choose_time_spine_read_node(self, time_spine_source: TimeSpineSource) -> ReadSqlSourceNode: + """Return the MetricTimeDimensionTransform time spine node needed to satisfy the specs.""" + return self._source_node_set.time_spine_read_nodes[time_spine_source.base_granularity.value] + + def _build_time_spine_node( + self, + queried_time_spine_specs: Sequence[TimeDimensionSpec], + where_filter_specs: Sequence[WhereFilterSpec] = (), + time_range_constraint: Optional[TimeRangeConstraint] = None, + ) -> DataflowPlanNode: + """Return the time spine node needed to satisfy the specs.""" + required_time_spine_spec_set = self.__get_required_linkable_specs( + queried_linkable_specs=LinkableSpecSet(time_dimension_specs=tuple(queried_time_spine_specs)), + filter_specs=where_filter_specs, + ) + required_time_spine_specs = required_time_spine_spec_set.time_dimension_specs + + time_spine_source = self._choose_time_spine_source(required_time_spine_specs) + time_spine_node = TransformTimeDimensionsNode.create( + parent_node=self._choose_time_spine_read_node(time_spine_source), + requested_time_dimension_specs=required_time_spine_specs, + ) + + # If the base grain of the time spine isn't selected, it will have duplicate rows that need deduping. + should_dedupe = ExpandedTimeGranularity.from_time_granularity(time_spine_source.base_granularity) not in { + spec.time_granularity for spec in queried_time_spine_specs + } + + return self._build_pre_aggregation_plan( + source_node=time_spine_node, + filter_to_specs=InstanceSpecSet(time_dimension_specs=tuple(queried_time_spine_specs)), + custom_granularity_specs=required_time_spine_spec_set.time_dimension_specs_with_custom_grain, + time_range_constraint=time_range_constraint, + where_filter_specs=where_filter_specs, + distinct=should_dedupe, + ) + + def _sort_by_base_granularity(self, time_dimension_specs: Sequence[TimeDimensionSpec]) -> List[TimeDimensionSpec]: + """Sort the time dimensions by their base granularity. + + Specs with date part will come after specs without it. Standard grains will come before custom. + """ + return sorted( + time_dimension_specs, + key=lambda spec: ( + spec.date_part is not None, + spec.time_granularity.is_custom_granularity, + spec.time_granularity.base_granularity.to_int(), + ), + ) diff --git a/metricflow/dataflow/builder/source_node.py b/metricflow/dataflow/builder/source_node.py index 0192e21277..68f9f82d50 100644 --- a/metricflow/dataflow/builder/source_node.py +++ b/metricflow/dataflow/builder/source_node.py @@ -36,6 +36,7 @@ class SourceNodeSet: # Semantic models are 1:1 mapped to a ReadSqlSourceNode. source_nodes_for_group_by_item_queries: Tuple[DataflowPlanNode, ...] + # TODO: maybe this didn't need to have string keys, check later # Provides time spines that can be used to satisfy time spine joins, organized by granularity name. time_spine_read_nodes: Mapping[str, ReadSqlSourceNode] diff --git a/metricflow/dataflow/nodes/join_to_time_spine.py b/metricflow/dataflow/nodes/join_to_time_spine.py index fd86503813..b33a3ff6d1 100644 --- a/metricflow/dataflow/nodes/join_to_time_spine.py +++ b/metricflow/dataflow/nodes/join_to_time_spine.py @@ -8,9 +8,7 @@ from dbt_semantic_interfaces.type_enums import TimeGranularity from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix from metricflow_semantics.dag.mf_dag import DisplayedProperty -from metricflow_semantics.filters.time_constraint import TimeRangeConstraint from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec -from metricflow_semantics.specs.where_filter.where_filter_spec import WhereFilterSpec from metricflow_semantics.sql.sql_join_type import SqlJoinType from metricflow_semantics.visitor import VisitorOutputT @@ -25,17 +23,17 @@ class JoinToTimeSpineNode(DataflowPlanNode, ABC): Attributes: requested_agg_time_dimension_specs: Time dimensions requested in the query. join_type: Join type to use when joining to time spine. - time_range_constraint: Time range to constrain the time spine to. + join_on_time_dimension_spec: The time dimension to use in the join ON condition. offset_window: Time window to offset the parent dataset by when joining to time spine. offset_to_grain: Granularity period to offset the parent dataset to when joining to time spine. """ + time_spine_node: DataflowPlanNode requested_agg_time_dimension_specs: Sequence[TimeDimensionSpec] + join_on_time_dimension_spec: TimeDimensionSpec join_type: SqlJoinType - time_range_constraint: Optional[TimeRangeConstraint] offset_window: Optional[MetricTimeWindow] offset_to_grain: Optional[TimeGranularity] - time_spine_filters: Optional[Sequence[WhereFilterSpec]] = None def __post_init__(self) -> None: # noqa: D105 super().__post_init__() @@ -51,21 +49,21 @@ def __post_init__(self) -> None: # noqa: D105 @staticmethod def create( # noqa: D102 parent_node: DataflowPlanNode, + time_spine_node: DataflowPlanNode, requested_agg_time_dimension_specs: Sequence[TimeDimensionSpec], + join_on_time_dimension_spec: TimeDimensionSpec, join_type: SqlJoinType, - time_range_constraint: Optional[TimeRangeConstraint] = None, offset_window: Optional[MetricTimeWindow] = None, offset_to_grain: Optional[TimeGranularity] = None, - time_spine_filters: Optional[Sequence[WhereFilterSpec]] = None, ) -> JoinToTimeSpineNode: return JoinToTimeSpineNode( parent_nodes=(parent_node,), + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=tuple(requested_agg_time_dimension_specs), + join_on_time_dimension_spec=join_on_time_dimension_spec, join_type=join_type, - time_range_constraint=time_range_constraint, offset_window=offset_window, offset_to_grain=offset_to_grain, - time_spine_filters=time_spine_filters, ) @classmethod @@ -83,20 +81,13 @@ def description(self) -> str: # noqa: D102 def displayed_properties(self) -> Sequence[DisplayedProperty]: # noqa: D102 props = tuple(super().displayed_properties) + ( DisplayedProperty("requested_agg_time_dimension_specs", self.requested_agg_time_dimension_specs), + DisplayedProperty("join_on_time_dimension_spec", self.join_on_time_dimension_spec), DisplayedProperty("join_type", self.join_type), ) if self.offset_window: props += (DisplayedProperty("offset_window", self.offset_window),) if self.offset_to_grain: props += (DisplayedProperty("offset_to_grain", self.offset_to_grain),) - if self.time_range_constraint: - props += (DisplayedProperty("time_range_constraint", self.time_range_constraint),) - if self.time_spine_filters: - props += ( - DisplayedProperty( - "time_spine_filters", [time_spine_filter.where_sql for time_spine_filter in self.time_spine_filters] - ), - ) return props @property @@ -106,22 +97,21 @@ def parent_node(self) -> DataflowPlanNode: # noqa: D102 def functionally_identical(self, other_node: DataflowPlanNode) -> bool: # noqa: D102 return ( isinstance(other_node, self.__class__) - and other_node.time_range_constraint == self.time_range_constraint and other_node.offset_window == self.offset_window and other_node.offset_to_grain == self.offset_to_grain and other_node.requested_agg_time_dimension_specs == self.requested_agg_time_dimension_specs + and other_node.join_on_time_dimension_spec == self.join_on_time_dimension_spec and other_node.join_type == self.join_type - and other_node.time_spine_filters == self.time_spine_filters ) def with_new_parents(self, new_parent_nodes: Sequence[DataflowPlanNode]) -> JoinToTimeSpineNode: # noqa: D102 assert len(new_parent_nodes) == 1 return JoinToTimeSpineNode.create( parent_node=new_parent_nodes[0], + time_spine_node=self.time_spine_node, requested_agg_time_dimension_specs=self.requested_agg_time_dimension_specs, - time_range_constraint=self.time_range_constraint, offset_window=self.offset_window, offset_to_grain=self.offset_to_grain, join_type=self.join_type, - time_spine_filters=self.time_spine_filters, + join_on_time_dimension_spec=self.join_on_time_dimension_spec, ) diff --git a/metricflow/dataset/sql_dataset.py b/metricflow/dataset/sql_dataset.py index 2b86eb4799..6b52f57411 100644 --- a/metricflow/dataset/sql_dataset.py +++ b/metricflow/dataset/sql_dataset.py @@ -147,6 +147,22 @@ def instance_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> """Given the name of the time dimension, return the instance associated with it in the data set.""" return self.instances_for_time_dimensions((time_dimension_spec,))[0] + def instance_from_time_dimension_grain_and_date_part( + self, time_dimension_spec: TimeDimensionSpec + ) -> TimeDimensionInstance: + """Find instance in dataset that matches the grain and date part of the given time dimension spec.""" + for time_dimension_instance in self.instance_set.time_dimension_instances: + if ( + time_dimension_instance.spec.time_granularity == time_dimension_spec.time_granularity + and time_dimension_instance.spec.date_part == time_dimension_spec.date_part + ): + return time_dimension_instance + + raise RuntimeError( + f"Did not find a time dimension instance with matching grain and date part for spec: {time_dimension_spec}\n" + f"Instances available: {self.instance_set.time_dimension_instances}" + ) + def column_association_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> ColumnAssociation: """Given the name of the time dimension, return the set of columns associated with it in the data set.""" return self.instance_for_time_dimension(time_dimension_spec).associated_column diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 8d51fe639e..0c4dd3c878 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -36,6 +36,7 @@ from metricflow_semantics.specs.metadata_spec import MetadataSpec 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.specs.where_filter.where_filter_spec import WhereFilterSpec from metricflow_semantics.sql.sql_join_type import SqlJoinType from metricflow_semantics.sql.sql_table import SqlTable @@ -1111,7 +1112,7 @@ def visit_constrain_time_range_node(self, node: ConstrainTimeRangeNode) -> SqlDa [ instance for instance in from_data_set.metric_time_dimension_instances - if not instance.spec.time_granularity.is_custom_granularity + if not instance.spec.time_granularity.is_custom_granularity and not instance.spec.date_part ], key=lambda x: x.spec.time_granularity.base_granularity.to_int(), ) @@ -1371,97 +1372,73 @@ def _choose_instance_for_time_spine_join( def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet: # noqa: D102 parent_data_set = node.parent_node.accept(self) parent_alias = self._next_unique_table_alias() - - agg_time_dimension_instances = parent_data_set.instances_for_time_dimensions( - node.requested_agg_time_dimension_specs - ) - - # Select the dimension for the join from the parent node because it may not have been included in the request. - # Default to using metric_time for the join if it was requested, otherwise use the agg_time_dimension. - included_metric_time_instances = [ - instance for instance in agg_time_dimension_instances if instance.spec.is_metric_time - ] - if included_metric_time_instances: - join_on_time_dimension_sample = included_metric_time_instances[0].spec - else: - join_on_time_dimension_sample = agg_time_dimension_instances[0].spec - agg_time_dimension_instance_for_join = self._choose_instance_for_time_spine_join( - [ - instance - for instance in parent_data_set.instance_set.time_dimension_instances - if instance.spec.element_name == join_on_time_dimension_sample.element_name - and instance.spec.entity_links == join_on_time_dimension_sample.entity_links - ] - ) - if agg_time_dimension_instance_for_join not in agg_time_dimension_instances: - agg_time_dimension_instances = (agg_time_dimension_instance_for_join,) + agg_time_dimension_instances - - # Build time spine data set with just the agg_time_dimension instance needed for the join. + time_spine_data_set = node.time_spine_node.accept(self) time_spine_alias = self._next_unique_table_alias() - time_spine_dataset = self._make_time_spine_data_set( - agg_time_dimension_instances=agg_time_dimension_instances, - time_range_constraint=node.time_range_constraint, - time_spine_where_constraints=node.time_spine_filters or (), - ) + + required_agg_time_dimension_specs = tuple(node.requested_agg_time_dimension_specs) + if node.join_on_time_dimension_spec not in node.requested_agg_time_dimension_specs: + required_agg_time_dimension_specs += (node.join_on_time_dimension_spec,) # Build join expression. + join_column_name = self._column_association_resolver.resolve_spec(node.join_on_time_dimension_spec).column_name join_description = SqlQueryPlanJoinBuilder.make_join_to_time_spine_join_description( node=node, time_spine_alias=time_spine_alias, - agg_time_dimension_column_name=self._column_association_resolver.resolve_spec( - agg_time_dimension_instance_for_join.spec - ).column_name, + agg_time_dimension_column_name=join_column_name, parent_sql_select_node=parent_data_set.checked_sql_select_node, parent_alias=parent_alias, ) - # Remove time spine instances from parent instance set. - time_spine_instances = time_spine_dataset.instance_set - time_spine_specs = time_spine_instances.spec_set - parent_instance_set = parent_data_set.instance_set.transform(FilterElements(exclude_specs=time_spine_specs)) + # Build combined instance set. + time_spine_required_spec_set = InstanceSpecSet(time_dimension_specs=required_agg_time_dimension_specs) + parent_instance_set = parent_data_set.instance_set.transform( + FilterElements(exclude_specs=time_spine_required_spec_set) + ) + time_spine_instance_set = time_spine_data_set.instance_set.transform( + FilterElements(include_specs=time_spine_required_spec_set) + ) + output_instance_set = InstanceSet.merge([parent_instance_set, time_spine_instance_set]) - # Build select columns + # Build new simple select columns. select_columns = create_simple_select_columns_for_instance_sets( self._column_association_resolver, - OrderedDict({parent_alias: parent_instance_set, time_spine_alias: time_spine_dataset.instance_set}), + OrderedDict({parent_alias: parent_instance_set, time_spine_alias: time_spine_instance_set}), ) # If offset_to_grain is used, will need to filter down to rows that match selected granularities. - # Does not apply if one of the granularities selected matches the time spine column granularity. + # Does not apply if one of the granularities selected matches the smallest time spine column granularity. + # TODO: clarify the above comment - is it the time spine column grain? where_filter: Optional[SqlExpressionNode] = None need_where_filter = ( - node.offset_to_grain - and agg_time_dimension_instance_for_join.spec not in node.requested_agg_time_dimension_specs + node.offset_to_grain and node.join_on_time_dimension_spec not in node.requested_agg_time_dimension_specs ) + + # Filter down to one row per granularity period requested in the group by. Any other granularities + # included here will be filtered out before aggregation and so should not be included in where filter. if need_where_filter: join_column_expr = SqlColumnReferenceExpression.from_table_and_column_names( - table_alias=time_spine_alias, - column_name=agg_time_dimension_instance_for_join.associated_column.column_name, + table_alias=time_spine_alias, column_name=join_column_name ) - for time_spine_instance in time_spine_instances.as_tuple: - # Filter down to one row per granularity period requested in the group by. Any other granularities - # included here will be filtered out in later nodes so should not be included in where filter. - if need_where_filter and time_spine_instance.spec in node.requested_agg_time_dimension_specs: - column_to_filter_expr = SqlColumnReferenceExpression.from_table_and_column_names( - table_alias=time_spine_alias, column_name=time_spine_instance.associated_column.column_name - ) - new_where_filter = SqlComparisonExpression.create( - left_expr=column_to_filter_expr, comparison=SqlComparison.EQUALS, right_expr=join_column_expr - ) - where_filter = ( - SqlLogicalExpression.create( - operator=SqlLogicalOperator.OR, args=(where_filter, new_where_filter) - ) - if where_filter - else new_where_filter - ) + for requested_spec in node.requested_agg_time_dimension_specs: + column_name = self._column_association_resolver.resolve_spec(requested_spec).column_name + column_to_filter_expr = SqlColumnReferenceExpression.from_table_and_column_names( + table_alias=time_spine_alias, column_name=column_name + ) + new_where_filter = SqlComparisonExpression.create( + left_expr=column_to_filter_expr, comparison=SqlComparison.EQUALS, right_expr=join_column_expr + ) + where_filter = ( + SqlLogicalExpression.create(operator=SqlLogicalOperator.OR, args=(where_filter, new_where_filter)) + if where_filter + else new_where_filter + ) return SqlDataSet( - instance_set=InstanceSet.merge([time_spine_dataset.instance_set, parent_instance_set]), + instance_set=output_instance_set, sql_select_node=SqlSelectStatementNode.create( description=node.description, select_columns=select_columns, - from_source=time_spine_dataset.checked_sql_select_node, + from_source=time_spine_data_set.checked_sql_select_node, from_source_alias=time_spine_alias, join_descs=(join_description,), where=where_filter, @@ -1487,7 +1464,53 @@ def _get_custom_granularity_column_name(self, custom_granularity_name: str) -> s ) def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> SqlDataSet: # noqa: D102 - raise NotImplementedError + parent_data_set = node.parent_node.accept(self) + parent_alias = self._next_unique_table_alias() + + new_instances: Tuple[TimeDimensionInstance, ...] = () + new_select_columns: Tuple[SqlSelectColumn, ...] = () + specs_to_remove_from_parent: Set[TimeDimensionSpec] = set() + for spec in node.requested_time_dimension_specs: + # Find the instance in the parent data set with matching grain & date part. + old_instance = parent_data_set.instance_from_time_dimension_grain_and_date_part(spec) + + # Build new instance & select column to match requested spec. + new_instance = TimeDimensionInstance( + defined_from=old_instance.defined_from, + associated_columns=(self._column_association_resolver.resolve_spec(spec),), + spec=spec, + ) + new_expr = SqlColumnReferenceExpression.from_table_and_column_names( + table_alias=parent_alias, column_name=old_instance.associated_column.column_name + ) + new_select_column = SqlSelectColumn(expr=new_expr, column_alias=new_instance.associated_column.column_name) + specs_to_remove_from_parent.add(old_instance.spec) + new_instances += (new_instance,) + new_select_columns += (new_select_column,) + + # Build full output instance set. + filtered_parent_instance_set = parent_data_set.instance_set.transform( + FilterElements(include_specs=InstanceSpecSet(time_dimension_specs=tuple(specs_to_remove_from_parent))) + ) + new_instance_set = InstanceSet(time_dimension_instances=new_instances) + transformed_instance_set = InstanceSet.merge([filtered_parent_instance_set, new_instance_set]) + + # Build final select columns. + filtered_parent_select_columns = create_simple_select_columns_for_instance_sets( + column_resolver=self._column_association_resolver, + table_alias_to_instance_set=OrderedDict({parent_alias: filtered_parent_instance_set}), + ) + transformed_select_columns = new_select_columns + filtered_parent_select_columns + + return SqlDataSet( + instance_set=transformed_instance_set, + sql_select_node=SqlSelectStatementNode.create( + description=node.description, + select_columns=transformed_select_columns, + from_source=parent_data_set.checked_sql_select_node, + from_source_alias=parent_alias, + ), + ) def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> SqlDataSet: # noqa: D102 parent_data_set = node.parent_node.accept(self) @@ -1549,6 +1572,7 @@ def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNod select_columns=parent_data_set.checked_sql_select_node.select_columns + time_spine_select_columns, from_source=parent_data_set.checked_sql_select_node.from_source, from_source_alias=parent_alias, + cte_sources=parent_data_set.checked_sql_select_node.cte_sources, join_descs=parent_data_set.checked_sql_select_node.join_descs + (join_description,), where=parent_data_set.checked_sql_select_node.where, group_bys=parent_data_set.checked_sql_select_node.group_bys, 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 f0cde24ff7..d6c0d85baf 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 @@ -6,25 +6,47 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_6.visits), 0) AS visits - , COALESCE(MAX(subq_19.buys), 0) AS buys + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_7.visits), 0) AS visits + , COALESCE(MAX(subq_21.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.visits AS visits FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +142,137 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day + ) subq_7 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.buys AS buys + subq_20.metric_time__day AS metric_time__day + , subq_17.buys AS buys FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_18.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_18 - ) subq_17 + subq_19.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_18.ds__day AS metric_time__day + , subq_18.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + ) subq_19 + ) subq_20 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_15.metric_time__day - , SUM(subq_15.buys) AS buys + subq_16.metric_time__day + , SUM(subq_16.buys) AS buys FROM ( -- Pass Only Elements: ['buys', 'metric_time__day'] SELECT - subq_14.metric_time__day - , subq_14.buys + subq_15.metric_time__day + , subq_15.buys FROM ( -- Find conversions for user within the range of 7 day SELECT - subq_13.metric_time__day - , subq_13.user - , subq_13.buys - , subq_13.visits + subq_14.metric_time__day + , subq_14.user + , subq_14.buys + , subq_14.visits FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( + FIRST_VALUE(subq_10.visits) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_9.metric_time__day) OVER ( + , FIRST_VALUE(subq_10.metric_time__day) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_9.user) OVER ( + , FIRST_VALUE(subq_10.user) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys + , subq_13.mf_internal_uuid AS mf_internal_uuid + , subq_13.buys AS buys FROM ( -- Pass Only Elements: ['visits', 'metric_time__day', 'user'] SELECT - subq_8.metric_time__day - , subq_8.user - , subq_8.visits + subq_9.metric_time__day + , subq_9.user + , subq_9.visits FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.visit__ds__day - , subq_7.visit__ds__week - , subq_7.visit__ds__month - , subq_7.visit__ds__quarter - , subq_7.visit__ds__year - , subq_7.visit__ds__extract_year - , subq_7.visit__ds__extract_quarter - , subq_7.visit__ds__extract_month - , subq_7.visit__ds__extract_day - , subq_7.visit__ds__extract_dow - , subq_7.visit__ds__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.user - , subq_7.session - , subq_7.visit__user - , subq_7.visit__session - , subq_7.referrer_id - , subq_7.visit__referrer_id - , subq_7.visits - , subq_7.visitors + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.visit__ds__day + , subq_8.visit__ds__week + , subq_8.visit__ds__month + , subq_8.visit__ds__quarter + , subq_8.visit__ds__year + , subq_8.visit__ds__extract_year + , subq_8.visit__ds__extract_quarter + , subq_8.visit__ds__extract_month + , subq_8.visit__ds__extract_day + , subq_8.visit__ds__extract_dow + , subq_8.visit__ds__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.user + , subq_8.session + , subq_8.visit__user + , subq_8.visit__session + , subq_8.referrer_id + , subq_8.visit__referrer_id + , subq_8.visits + , subq_8.visitors FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -263,118 +307,118 @@ FROM ( , visits_source_src_28000.user_id AS visit__user , visits_source_src_28000.session_id AS visit__session FROM ***************************.fct_visits visits_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Add column with generated UUID SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.ds_month__month - , subq_11.ds_month__quarter - , subq_11.ds_month__year - , subq_11.ds_month__extract_year - , subq_11.ds_month__extract_quarter - , subq_11.ds_month__extract_month - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.buy__ds_month__month - , subq_11.buy__ds_month__quarter - , subq_11.buy__ds_month__year - , subq_11.buy__ds_month__extract_year - , subq_11.buy__ds_month__extract_quarter - , subq_11.buy__ds_month__extract_month - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers + subq_12.ds__day + , subq_12.ds__week + , subq_12.ds__month + , subq_12.ds__quarter + , subq_12.ds__year + , subq_12.ds__extract_year + , subq_12.ds__extract_quarter + , subq_12.ds__extract_month + , subq_12.ds__extract_day + , subq_12.ds__extract_dow + , subq_12.ds__extract_doy + , subq_12.ds_month__month + , subq_12.ds_month__quarter + , subq_12.ds_month__year + , subq_12.ds_month__extract_year + , subq_12.ds_month__extract_quarter + , subq_12.ds_month__extract_month + , subq_12.buy__ds__day + , subq_12.buy__ds__week + , subq_12.buy__ds__month + , subq_12.buy__ds__quarter + , subq_12.buy__ds__year + , subq_12.buy__ds__extract_year + , subq_12.buy__ds__extract_quarter + , subq_12.buy__ds__extract_month + , subq_12.buy__ds__extract_day + , subq_12.buy__ds__extract_dow + , subq_12.buy__ds__extract_doy + , subq_12.buy__ds_month__month + , subq_12.buy__ds_month__quarter + , subq_12.buy__ds_month__year + , subq_12.buy__ds_month__extract_year + , subq_12.buy__ds_month__extract_quarter + , subq_12.buy__ds_month__extract_month + , subq_12.metric_time__day + , subq_12.metric_time__week + , subq_12.metric_time__month + , subq_12.metric_time__quarter + , subq_12.metric_time__year + , subq_12.metric_time__extract_year + , subq_12.metric_time__extract_quarter + , subq_12.metric_time__extract_month + , subq_12.metric_time__extract_day + , subq_12.metric_time__extract_dow + , subq_12.metric_time__extract_doy + , subq_12.user + , subq_12.session_id + , subq_12.buy__user + , subq_12.buy__session_id + , subq_12.buys + , subq_12.buyers , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( -- Metric Time Dimension 'ds' SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_month__month - , subq_10.ds_month__quarter - , subq_10.ds_month__year - , subq_10.ds_month__extract_year - , subq_10.ds_month__extract_quarter - , subq_10.ds_month__extract_month - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.buy__ds_month__month - , subq_10.buy__ds_month__quarter - , subq_10.buy__ds_month__year - , subq_10.buy__ds_month__extract_year - , subq_10.buy__ds_month__extract_quarter - , subq_10.buy__ds_month__extract_month - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_month__month + , subq_11.ds_month__quarter + , subq_11.ds_month__year + , subq_11.ds_month__extract_year + , subq_11.ds_month__extract_quarter + , subq_11.ds_month__extract_month + , subq_11.buy__ds__day + , subq_11.buy__ds__week + , subq_11.buy__ds__month + , subq_11.buy__ds__quarter + , subq_11.buy__ds__year + , subq_11.buy__ds__extract_year + , subq_11.buy__ds__extract_quarter + , subq_11.buy__ds__extract_month + , subq_11.buy__ds__extract_day + , subq_11.buy__ds__extract_dow + , subq_11.buy__ds__extract_doy + , subq_11.buy__ds_month__month + , subq_11.buy__ds_month__quarter + , subq_11.buy__ds_month__year + , subq_11.buy__ds_month__extract_year + , subq_11.buy__ds_month__extract_quarter + , subq_11.buy__ds_month__extract_month + , subq_11.ds__day AS metric_time__day + , subq_11.ds__week AS metric_time__week + , subq_11.ds__month AS metric_time__month + , subq_11.ds__quarter AS metric_time__quarter + , subq_11.ds__year AS metric_time__year + , subq_11.ds__extract_year AS metric_time__extract_year + , subq_11.ds__extract_quarter AS metric_time__extract_quarter + , subq_11.ds__extract_month AS metric_time__extract_month + , subq_11.ds__extract_day AS metric_time__extract_day + , subq_11.ds__extract_dow AS metric_time__extract_dow + , subq_11.ds__extract_doy AS metric_time__extract_doy + , subq_11.user + , subq_11.session_id + , subq_11.buy__user + , subq_11.buy__session_id + , subq_11.buys + , subq_11.buyers FROM ( -- Read Elements From Semantic Model 'buys_source' SELECT @@ -420,30 +464,30 @@ FROM ( , buys_source_src_28000.user_id AS buy__user , buys_source_src_28000.session_id AS buy__session_id FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 + ) subq_11 + ) subq_12 + ) subq_13 ON ( - subq_9.user = subq_12.user + subq_10.user = subq_13.user ) AND ( ( - subq_9.metric_time__day <= subq_12.metric_time__day + subq_10.metric_time__day <= subq_13.metric_time__day ) AND ( - subq_9.metric_time__day > subq_12.metric_time__day - INTERVAL 7 day + subq_10.metric_time__day > subq_13.metric_time__day - INTERVAL 7 day ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_15.metric_time__day - ) subq_16 + subq_16.metric_time__day + ) subq_17 ON - subq_17.metric_time__day = subq_16.metric_time__day - ) subq_19 + subq_20.metric_time__day = subq_17.metric_time__day + ) subq_21 ON - subq_6.metric_time__day = subq_19.metric_time__day + subq_7.metric_time__day = subq_21.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) -) subq_20 + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) +) subq_22 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 f93bee27a4..38778a99ec 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 @@ -21,15 +21,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_27.visits), 0) AS visits - , COALESCE(MAX(subq_39.buys), 0) AS buys + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_30.visits), 0) AS visits + , COALESCE(MAX(subq_43.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_26.ds AS metric_time__day - , subq_24.visits AS visits - FROM ***************************.mf_time_spine subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_26.visits AS visits + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -40,16 +40,16 @@ FROM ( FROM sma_28019_cte sma_28019_cte GROUP BY metric_time__day - ) subq_24 + ) subq_26 ON - subq_26.ds = subq_24.metric_time__day - ) subq_27 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_26.metric_time__day + ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_38.ds AS metric_time__day - , subq_36.buys AS buys - FROM ***************************.mf_time_spine subq_38 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_39.buys AS buys + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -62,30 +62,30 @@ FROM ( SELECT DISTINCT FIRST_VALUE(sma_28019_cte.visits) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits , FIRST_VALUE(sma_28019_cte.metric_time__day) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day , FIRST_VALUE(sma_28019_cte.user) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_32.mf_internal_uuid AS mf_internal_uuid - , subq_32.buys AS buys + , subq_35.mf_internal_uuid AS mf_internal_uuid + , subq_35.buys AS buys FROM sma_28019_cte sma_28019_cte INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' @@ -97,26 +97,26 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_32 + ) subq_35 ON ( - sma_28019_cte.user = subq_32.user + sma_28019_cte.user = subq_35.user ) AND ( ( - sma_28019_cte.metric_time__day <= subq_32.metric_time__day + sma_28019_cte.metric_time__day <= subq_35.metric_time__day ) AND ( - sma_28019_cte.metric_time__day > subq_32.metric_time__day - INTERVAL 7 day + sma_28019_cte.metric_time__day > subq_35.metric_time__day - INTERVAL 7 day ) ) - ) subq_33 + ) subq_36 GROUP BY metric_time__day - ) subq_36 + ) subq_39 ON - subq_38.ds = subq_36.metric_time__day - ) subq_39 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_39.metric_time__day + ) subq_43 ON - subq_27.metric_time__day = subq_39.metric_time__day + subq_30.metric_time__day = subq_43.metric_time__day GROUP BY - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) -) subq_40 + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) +) subq_44 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 352d701da6..8896798545 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 @@ -6,19 +6,19 @@ docstring: - - + + - + - + @@ -34,11 +34,11 @@ docstring: - + - - + + @@ -51,11 +51,11 @@ docstring: - + - - - + + + @@ -66,21 +66,93 @@ docstring: - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -489,43 +561,115 @@ docstring: - + - - - + + + - - + + - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -533,50 +677,50 @@ docstring: - + - + - + - + - - + + - + - + - + - + - + - + - + @@ -594,19 +738,19 @@ docstring: - + - + - + - - + + @@ -614,239 +758,239 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1010,260 +1154,260 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1271,273 +1415,273 @@ docstring: - + - + - + - - - - - - - - - - - + - + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + 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 8e1e4d0e93..3620f1e974 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 @@ -8,43 +8,69 @@ sql_engine: DuckDB --- -- Re-aggregate Metric via Group By SELECT - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_10.booking__ds__month - , subq_10.metric_time__week - , FIRST_VALUE(subq_10.every_two_days_bookers_fill_nulls_with_0) OVER ( + subq_11.booking__ds__month + , subq_11.metric_time__week + , FIRST_VALUE(subq_11.every_two_days_bookers_fill_nulls_with_0) OVER ( PARTITION BY - subq_10.booking__ds__month - , subq_10.metric_time__week - ORDER BY subq_10.metric_time__day + subq_11.booking__ds__month + , subq_11.metric_time__week + ORDER BY subq_11.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Compute Metrics via Expressions SELECT - subq_9.booking__ds__month - , subq_9.metric_time__day - , subq_9.metric_time__week - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.booking__ds__month + , subq_10.metric_time__week + , subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.booking__ds__month AS booking__ds__month - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + subq_9.booking__ds__month AS booking__ds__month + , subq_9.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__month', 'metric_time__week', 'metric_time__day'] SELECT - DATE_TRUNC('month', subq_8.ds) AS booking__ds__month - , subq_8.ds AS metric_time__day - , DATE_TRUNC('week', subq_8.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__month + , subq_8.metric_time__week + , subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__month AS booking__ds__month + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day AS metric_time__day + , subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +403,11 @@ FROM ( , subq_5.metric_time__week ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day - ) subq_9 - ) subq_10 -) subq_11 + subq_9.metric_time__day = subq_6.metric_time__day + ) subq_10 + ) subq_11 +) subq_12 GROUP BY - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 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 3e431cfda5..0f2cf5d21c 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 @@ -27,38 +27,38 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('month', subq_20.ds) AS booking__ds__month - , subq_20.ds AS metric_time__day - , DATE_TRUNC('week', subq_20.ds) AS metric_time__week - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('month', time_spine_src_28006.ds) AS booking__ds__month + , DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week + , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_19.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - DATE_TRUNC('month', subq_15.ds) AS booking__ds__month - , subq_15.ds AS metric_time__day - , DATE_TRUNC('week', subq_15.ds) AS metric_time__week + DATE_TRUNC('month', subq_16.ds) AS booking__ds__month + , subq_16.ds AS metric_time__day + , DATE_TRUNC('week', subq_16.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 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_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) GROUP BY - DATE_TRUNC('month', subq_15.ds) - , subq_15.ds - , DATE_TRUNC('week', subq_15.ds) - ) subq_18 + DATE_TRUNC('month', subq_16.ds) + , subq_16.ds + , DATE_TRUNC('week', subq_16.ds) + ) subq_19 ON - subq_20.ds = subq_18.metric_time__day - ) subq_21 -) subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_19.metric_time__day + ) subq_23 +) subq_25 GROUP BY booking__ds__month , metric_time__week diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 3b2fd22074..55e53933e2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_9.metric_time__martian_day + , subq_9.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__martian_day AS metric_time__martian_day + subq_8.metric_time__martian_day AS metric_time__martian_day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__martian_day',] SELECT - subq_6.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_6 + subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + -- Join to Custom Granularity Dataset + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day AS ds__day + , subq_5.ds__martian_day AS ds__martian_day + , subq_6.martian_day AS metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_6 + ON + subq_5.ds__day = subq_6.ds + ) subq_7 GROUP BY - subq_6.martian_day - ) subq_5 + subq_7.metric_time__martian_day + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +265,5 @@ FROM ( subq_3.metric_time__martian_day ) subq_4 ON - subq_5.metric_time__martian_day = subq_4.metric_time__martian_day -) subq_7 + subq_8.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 2b21a9d62e..5e4069763c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,43 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_13.metric_time__martian_day AS metric_time__martian_day - , subq_12.bookings AS bookings_join_to_time_spine + subq_18.metric_time__martian_day AS metric_time__martian_day + , subq_14.bookings AS bookings_join_to_time_spine FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Join to Custom Granularity Dataset + -- Pass Only Elements: ['metric_time__martian_day',] SELECT - martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + subq_16.martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_16 + ON + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_16.ds GROUP BY - martian_day -) subq_13 + subq_16.martian_day +) subq_18 LEFT OUTER JOIN ( -- Metric Time Dimension 'ds' -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] -- Aggregate Measures SELECT - subq_9.martian_day AS metric_time__martian_day - , SUM(subq_8.bookings) AS bookings + subq_11.martian_day AS metric_time__martian_day + , SUM(subq_10.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT 1 AS bookings , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_10 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_11 ON - subq_8.ds__day = subq_9.ds + subq_10.ds__day = subq_11.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_11.martian_day +) subq_14 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_18.metric_time__martian_day = subq_14.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql index 7d92f42a89..1e88bd6e0e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__martian_day + subq_9.booking__ds__martian_day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.booking__ds__martian_day - , subq_7.bookings AS bookings_5_days_ago + subq_8.booking__ds__martian_day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.booking__ds__martian_day - , SUM(subq_6.bookings) AS bookings + subq_7.booking__ds__martian_day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__martian_day'] SELECT - subq_5.booking__ds__martian_day - , subq_5.bookings + subq_6.booking__ds__martian_day + , subq_6.bookings FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -101,7 +101,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,13 +123,35 @@ FROM ( , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99 , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - , subq_4.martian_day AS booking__ds__martian_day + , subq_5.martian_day AS booking__ds__martian_day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_3.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS booking__ds__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +348,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day + subq_4.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.booking__ds__day = subq_4.ds - ) subq_5 - ) subq_6 + subq_4.booking__ds__day = subq_5.ds + ) subq_6 + ) subq_7 GROUP BY - subq_6.booking__ds__martian_day - ) subq_7 -) subq_8 + subq_7.booking__ds__martian_day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 9b358e0937..817082e44e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql @@ -13,9 +13,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_13.martian_day AS booking__ds__martian_day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + subq_15.martian_day AS booking__ds__martian_day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,13 +23,13 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.booking__ds__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_11.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_13 + ***************************.mf_time_spine subq_15 ON - subq_12.ds = subq_13.ds + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_15.ds GROUP BY - subq_13.martian_day -) subq_17 + subq_15.martian_day +) subq_19 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 1a5b634111..27c20a697e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day + subq_10.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_5_days_ago + subq_9.metric_time__day + , subq_9.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.bookings) AS bookings + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_5.metric_time__martian_day - , subq_5.metric_time__day - , subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.ds_partitioned__day - , subq_5.ds_partitioned__week - , subq_5.ds_partitioned__month - , subq_5.ds_partitioned__quarter - , subq_5.ds_partitioned__year - , subq_5.ds_partitioned__extract_year - , subq_5.ds_partitioned__extract_quarter - , subq_5.ds_partitioned__extract_month - , subq_5.ds_partitioned__extract_day - , subq_5.ds_partitioned__extract_dow - , subq_5.ds_partitioned__extract_doy - , subq_5.paid_at__day - , subq_5.paid_at__week - , subq_5.paid_at__month - , subq_5.paid_at__quarter - , subq_5.paid_at__year - , subq_5.paid_at__extract_year - , subq_5.paid_at__extract_quarter - , subq_5.paid_at__extract_month - , subq_5.paid_at__extract_day - , subq_5.paid_at__extract_dow - , subq_5.paid_at__extract_doy - , subq_5.booking__ds__day - , subq_5.booking__ds__week - , subq_5.booking__ds__month - , subq_5.booking__ds__quarter - , subq_5.booking__ds__year - , subq_5.booking__ds__extract_year - , subq_5.booking__ds__extract_quarter - , subq_5.booking__ds__extract_month - , subq_5.booking__ds__extract_day - , subq_5.booking__ds__extract_dow - , subq_5.booking__ds__extract_doy - , subq_5.booking__ds_partitioned__day - , subq_5.booking__ds_partitioned__week - , subq_5.booking__ds_partitioned__month - , subq_5.booking__ds_partitioned__quarter - , subq_5.booking__ds_partitioned__year - , subq_5.booking__ds_partitioned__extract_year - , subq_5.booking__ds_partitioned__extract_quarter - , subq_5.booking__ds_partitioned__extract_month - , subq_5.booking__ds_partitioned__extract_day - , subq_5.booking__ds_partitioned__extract_dow - , subq_5.booking__ds_partitioned__extract_doy - , subq_5.booking__paid_at__day - , subq_5.booking__paid_at__week - , subq_5.booking__paid_at__month - , subq_5.booking__paid_at__quarter - , subq_5.booking__paid_at__year - , subq_5.booking__paid_at__extract_year - , subq_5.booking__paid_at__extract_quarter - , subq_5.booking__paid_at__extract_month - , subq_5.booking__paid_at__extract_day - , subq_5.booking__paid_at__extract_dow - , subq_5.booking__paid_at__extract_doy - , subq_5.metric_time__week - , subq_5.metric_time__month - , subq_5.metric_time__quarter - , subq_5.metric_time__year - , subq_5.metric_time__extract_year - , subq_5.metric_time__extract_quarter - , subq_5.metric_time__extract_month - , subq_5.metric_time__extract_day - , subq_5.metric_time__extract_dow - , subq_5.metric_time__extract_doy - , subq_5.listing - , subq_5.guest - , subq_5.host - , subq_5.booking__listing - , subq_5.booking__guest - , subq_5.booking__host - , subq_5.is_instant - , subq_5.booking__is_instant - , subq_5.bookings - , subq_5.instant_bookings - , subq_5.booking_value - , subq_5.max_booking_value - , subq_5.min_booking_value - , subq_5.bookers - , subq_5.average_booking_value - , subq_5.referred_bookings - , subq_5.median_booking_value - , subq_5.booking_value_p99 - , subq_5.discrete_booking_value_p99 - , subq_5.approximate_continuous_booking_value_p99 - , subq_5.approximate_discrete_booking_value_p99 + subq_6.metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__extract_doy + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -203,7 +203,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -225,13 +225,35 @@ FROM ( , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99 , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - , subq_4.martian_day AS metric_time__martian_day + , subq_5.martian_day AS metric_time__martian_day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +450,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.metric_time__day = subq_4.ds - ) subq_5 + subq_4.metric_time__day = subq_5.ds + ) subq_6 WHERE metric_time__martian_day = '2020-01-01' - ) subq_6 - ) subq_7 + ) subq_7 + ) subq_8 GROUP BY - subq_7.metric_time__day - ) subq_8 -) subq_9 + subq_8.metric_time__day + ) subq_9 +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index a74e4042e7..b811aecf0c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -18,10 +18,10 @@ FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset SELECT - subq_13.ds AS metric_time__day - , subq_11.bookings AS bookings - , subq_14.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_13 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_12.bookings AS bookings + , subq_16.martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -29,15 +29,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_12 ON - subq_13.ds - INTERVAL 5 day = subq_11.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_12.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_14 + ***************************.mf_time_spine subq_16 ON - subq_13.ds = subq_14.ds - ) subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_16.ds + ) subq_17 WHERE metric_time__martian_day = '2020-01-01' GROUP BY metric_time__day -) subq_19 +) subq_21 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 f8197f144b..895447530c 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 @@ -60,7 +60,7 @@ docstring: - + @@ -78,6 +78,11 @@ docstring: + + + + + 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 dbe84cd5db..7b83fc6723 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 @@ -26,7 +26,7 @@ docstring: - + @@ -44,6 +44,11 @@ docstring: + + + + + 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 88e7bab66e..761d9b1cf3 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 @@ -24,7 +24,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -42,6 +42,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + 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 55d4a16786..50fb6005a4 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 @@ -25,7 +25,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -43,6 +43,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + 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 ab0c43a9dd..9832566a7e 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 @@ -31,6 +31,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -79,13 +84,18 @@ test_filename: test_dataflow_plan_builder.py + + + + + - + @@ -103,6 +113,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + 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 29dcfc8ad3..eafb91229f 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 @@ -58,7 +58,7 @@ docstring: - + @@ -71,13 +71,12 @@ docstring: + + + + + - - - - - - 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 474bca4b1e..c4855938b4 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 @@ -20,6 +20,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + 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 c4c72c23ed..8934a0311a 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 @@ -19,6 +19,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -44,7 +49,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -62,6 +67,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + 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 85ac6913de..24643e555e 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 @@ -112,7 +112,7 @@ docstring: - + @@ -170,6 +170,11 @@ docstring: + + + + + 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 5734f04cda..1879434f9d 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 @@ -114,7 +114,7 @@ docstring: - + @@ -175,6 +175,11 @@ docstring: + + + + + @@ -246,7 +251,7 @@ docstring: - + 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 c7ebdd463f..60fbb56c3e 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 @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_12.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.bookers AS every_2_days_bookers_2_days_ago + subq_11.metric_time__day + , subq_11.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , COUNT(DISTINCT subq_9.bookers) AS bookers + subq_10.metric_time__day + , COUNT(DISTINCT subq_10.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.bookers + subq_9.metric_time__day + , subq_9.bookers FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.metric_time__week + , subq_8.metric_time__month + , subq_8.metric_time__quarter + , subq_8.metric_time__year + , subq_8.metric_time__extract_year + , subq_8.metric_time__extract_quarter + , subq_8.metric_time__extract_month + , subq_8.metric_time__extract_day + , subq_8.metric_time__extract_dow + , subq_8.metric_time__extract_doy + , subq_8.metric_time__day + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -224,11 +224,33 @@ FROM ( , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +561,12 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_8 - ) subq_9 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_9 + ) subq_10 GROUP BY - subq_9.metric_time__day - ) subq_10 -) subq_11 + subq_10.metric_time__day + ) subq_11 +) subq_12 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 c9708287a0..c32774600a 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 @@ -13,27 +13,27 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_18.ds AS metric_time__day - , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_18 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , COUNT(DISTINCT subq_17.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_15.ds AS metric_time__day + subq_16.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 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_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) - ) subq_16 + ) subq_17 ON - subq_18.ds - INTERVAL 2 day = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_17.metric_time__day + WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index fda110dcfa..48ee8dbe02 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month + subq_8.metric_time__month , bookings_last_month AS bookings_last_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , subq_6.bookings_monthly AS bookings_last_month + subq_7.metric_time__month + , subq_7.bookings_monthly AS bookings_last_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__month - , SUM(subq_5.bookings_monthly) AS bookings_monthly + subq_6.metric_time__month + , SUM(subq_6.bookings_monthly) AS bookings_monthly FROM ( -- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] SELECT - subq_4.metric_time__month - , subq_4.bookings_monthly + subq_5.metric_time__month + , subq_5.bookings_monthly FROM ( -- Join to Time Spine Dataset SELECT @@ -41,18 +41,40 @@ FROM ( , subq_1.metric_time__extract_year AS metric_time__extract_year , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter , subq_1.metric_time__extract_month AS metric_time__extract_month - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.booking_monthly__listing AS booking_monthly__listing , subq_1.bookings_monthly AS bookings_monthly FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month', 'metric_time__month'] SELECT - DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 + subq_3.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_16006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_16006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_16006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_16006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_16006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_16006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_16006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_16006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_16006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_16006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_16006.ds) AS ds__extract_doy + , time_spine_src_16006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_16006 + ) subq_2 + ) subq_3 GROUP BY - DATE_TRUNC('month', subq_3.ds) - ) subq_2 + subq_3.metric_time__month + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -99,10 +121,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month - ) subq_4 - ) subq_5 + subq_4.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__month - ) subq_6 -) subq_7 + subq_6.metric_time__month + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 4c78ac742c..d7a896562a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -12,20 +12,22 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.metric_time__month AS metric_time__month + subq_13.metric_time__month AS metric_time__month , SUM(monthly_bookings_source_src_16000.bookings_monthly) AS bookings_last_month FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__month', 'metric_time__month'] SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine time_spine_src_16006 GROUP BY DATE_TRUNC('month', ds) - ) subq_10 + ) subq_13 INNER JOIN ***************************.fct_bookings_extended_monthly monthly_bookings_source_src_16000 ON - subq_10.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + subq_13.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) GROUP BY - subq_10.metric_time__month -) subq_15 + subq_13.metric_time__month +) subq_17 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 245d56f88d..c12c3da26b 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 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 d7456bd9df..dc912062d7 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_19.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) +) subq_29 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 bf9ad8dd43..1b9b87061a 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__week + subq_14.metric_time__week , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) AS metric_time__week , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__week - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__week + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__week - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__week + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__week'] SELECT - subq_9.metric_time__week - , subq_9.bookings + subq_10.metric_time__week + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + , subq_9.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__week', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - , DATE_TRUNC('week', subq_8.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__week + , subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__week AS metric_time__week + , subq_7.ds__day AS metric_time__day + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +570,16 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - WHERE subq_7.metric_time__week = subq_7.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + WHERE subq_9.metric_time__week = subq_9.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__week - ) subq_11 - ) subq_12 + subq_11.metric_time__week + ) subq_12 + ) subq_13 ON - subq_4.metric_time__week = subq_12.metric_time__week + subq_4.metric_time__week = subq_13.metric_time__week GROUP BY - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) -) subq_13 + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) +) subq_14 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 cfa6d1f5e0..e34f57bac4 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_28.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('week', ds) AS metric_time__week , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__week - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__week'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('week', subq_22.ds) AS metric_time__week - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,15 +46,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 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', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = DATE_TRUNC('day', time_spine_src_28006.ds) GROUP BY - DATE_TRUNC('week', subq_22.ds) - ) subq_26 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__week = subq_26.metric_time__week + subq_19.metric_time__week = subq_28.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) -) subq_27 + COALESCE(subq_19.metric_time__week, subq_28.metric_time__week) +) subq_29 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 3ec3c55d3d..7d18b00108 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 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 18cde7417b..68f4871ba3 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_19.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) +) subq_29 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 792cbdb254..257b9ac92d 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__quarter + subq_14.metric_time__quarter , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) AS metric_time__quarter + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) AS metric_time__quarter , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__quarter - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__quarter + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__quarter - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__quarter + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__quarter'] SELECT - subq_9.metric_time__quarter - , subq_9.bookings + subq_10.metric_time__quarter + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__quarter AS metric_time__quarter + , subq_9.metric_time__quarter AS metric_time__quarter + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__quarter', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - , DATE_TRUNC('quarter', subq_8.ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__quarter + , subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day AS metric_time__day + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +570,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__quarter - ) subq_11 - ) subq_12 + subq_11.metric_time__quarter + ) subq_12 + ) subq_13 ON - subq_4.metric_time__quarter = subq_12.metric_time__quarter + subq_4.metric_time__quarter = subq_13.metric_time__quarter GROUP BY - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) -) subq_13 + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) +) subq_14 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 42b79f2c69..6724277d31 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_28.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('quarter', ds) AS metric_time__quarter , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__quarter - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__quarter'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('quarter', subq_22.ds) AS metric_time__quarter - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_22.ds) - ) subq_26 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__quarter = subq_26.metric_time__quarter + subq_19.metric_time__quarter = subq_28.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) -) subq_27 + COALESCE(subq_19.metric_time__quarter, subq_28.metric_time__quarter) +) subq_29 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 50ff9446a0..30c5930601 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 @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__day + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +352,258 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 + subq_6.metric_time__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_1_month_ago + subq_16.metric_time__day + , subq_16.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__day + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_14.metric_time__day + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__year AS metric_time__year - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__year AS metric_time__year + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__day AS metric_time__day + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -652,18 +696,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 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 cc78d48928..b1216a35d5 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 @@ -9,18 +9,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_36.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_20.ds AS metric_time__day - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_20.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,21 +28,21 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_29.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -50,14 +50,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 1 month = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_36 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_27.metric_time__day = subq_36.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) +) subq_37 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 afc7ce6516..01818f2b91 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 @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__year + subq_18.metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) AS metric_time__year - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) AS metric_time__year + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__year - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__year + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -105,8 +105,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,12 +129,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__year', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__year + , subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__year AS metric_time__year + , subq_2.ds__day AS metric_time__day + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +355,262 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE subq_2.metric_time__year = subq_2.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + WHERE subq_4.metric_time__year = subq_4.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_6.metric_time__year + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__year - , subq_14.bookings AS bookings_1_month_ago + subq_16.metric_time__year + , subq_16.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__year - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__year + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_12.metric_time__year - , subq_12.bookings + subq_14.metric_time__year + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_10.metric_time__year AS metric_time__year - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__year AS metric_time__year + , subq_13.metric_time__day AS metric_time__day + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__year', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day - , DATE_TRUNC('year', subq_11.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__year + , subq_12.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__year AS metric_time__year + , subq_11.ds__day AS metric_time__day + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -655,18 +703,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__year - ) subq_14 - ) subq_15 + subq_15.metric_time__year + ) subq_16 + ) subq_17 ON - subq_7.metric_time__year = subq_15.metric_time__year + subq_8.metric_time__year = subq_17.metric_time__year GROUP BY - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) -) subq_16 + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) +) subq_18 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 b31f530528..a7455ee806 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 @@ -9,18 +9,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_36.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_36.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_20.ds) AS metric_time__year - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_20.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,22 +28,22 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 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', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = DATE_TRUNC('day', time_spine_src_28006.ds) GROUP BY - DATE_TRUNC('year', subq_20.ds) - ) subq_24 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_28.ds) AS metric_time__year - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_29.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -51,14 +51,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 1 month = subq_29.metric_time__day GROUP BY - DATE_TRUNC('year', subq_28.ds) - ) subq_32 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_36 ON - subq_24.metric_time__year = subq_32.metric_time__year + subq_27.metric_time__year = subq_36.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) -) subq_33 + COALESCE(subq_27.metric_time__year, subq_36.metric_time__year) +) subq_37 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 e88a2f9f3e..b30984419f 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) AS metric_time__day + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) AS metric_time__day , MAX(subq_5.bookings) AS bookings - , MAX(subq_14.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -333,119 +333,119 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.bookings AS bookings_2_weeks_ago + subq_14.metric_time__day + , subq_14.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , SUM(subq_12.bookings) AS bookings + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.bookings + subq_12.metric_time__day + , subq_12.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_10.metric_time__day - , subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.metric_time__day + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -525,7 +525,7 @@ FROM ( , subq_7.metric_time__extract_day AS metric_time__extract_day , subq_7.metric_time__extract_dow AS metric_time__extract_dow , subq_7.metric_time__extract_doy AS metric_time__extract_doy - , subq_8.metric_time__day AS metric_time__day + , subq_10.metric_time__day AS metric_time__day , subq_7.listing AS listing , subq_7.guest AS guest , subq_7.host AS host @@ -548,11 +548,33 @@ FROM ( , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_9.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_9 - ) subq_8 + subq_9.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_8.ds__day AS metric_time__day + , subq_8.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +771,17 @@ FROM ( ) subq_6 ) subq_7 ON - subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day - ) subq_10 + subq_10.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day + ) subq_11 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__day - ) subq_13 - ) subq_14 + subq_13.metric_time__day + ) subq_14 + ) subq_15 ON - subq_5.metric_time__day = subq_14.metric_time__day + subq_5.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) +) subq_16 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 66f5fe7c5e..3228f97b25 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_30.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -27,11 +27,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_17 + ) subq_18 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_21 + ) subq_22 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -43,9 +43,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_25.ds AS metric_time__day - , subq_23.bookings AS bookings - FROM ***************************.mf_time_spine subq_25 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_24.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -53,16 +53,16 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_24 ON - subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day - ) subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_30 + ) subq_32 ON - subq_21.metric_time__day = subq_30.metric_time__day + subq_22.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_22.metric_time__day, subq_32.metric_time__day) +) subq_33 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 7a0c96d981..26d1984398 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 @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_11.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , subq_9.bookers AS every_2_days_bookers_2_days_ago + subq_10.metric_time__day + , subq_10.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , COUNT(DISTINCT subq_8.bookers) AS bookers + subq_9.metric_time__day + , COUNT(DISTINCT subq_9.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookers + subq_8.metric_time__day + , subq_8.bookers FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -123,11 +123,33 @@ FROM ( , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +460,10 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - ) subq_8 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + ) subq_9 GROUP BY - subq_8.metric_time__day - ) subq_9 -) subq_10 + subq_9.metric_time__day + ) subq_10 +) subq_11 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 47db02e9dd..09aae77d1c 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 @@ -12,26 +12,26 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_17 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_14.ds AS metric_time__day + subq_15.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day ) - ) subq_15 + ) subq_16 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + DATE_TRUNC('day', time_spine_src_28006.ds) +) subq_23 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 5e5ede6026..e276f3034d 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 @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.booking__ds__day - , subq_6.booking_value + subq_7.booking__ds__day + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.booking__ds__day - , SUM(subq_5.booking_value) AS booking_value + subq_6.booking__ds__day + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__ds__day'] SELECT - subq_4.booking__ds__day - , subq_4.booking_value + subq_5.booking__ds__day + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_3.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS booking__ds__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +352,129 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + subq_4.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.booking__ds__day - ) subq_6 - ) subq_7 + subq_6.booking__ds__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookers + subq_12.booking__ds__day + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.booking__ds__day + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookers + subq_10.booking__ds__day + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -545,15 +567,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_7.booking__ds__day = subq_12.booking__ds__day + subq_8.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) +) subq_14 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 d916d9e538..17ac2ea6ad 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 @@ -9,25 +9,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_28.bookers) AS bookers FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS booking__ds__day + DATE_TRUNC('day', time_spine_src_28006.ds) AS booking__ds__day , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,9 +40,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_26 + ) subq_28 ON - subq_21.booking__ds__day = subq_26.booking__ds__day + subq_23.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_23.booking__ds__day, subq_28.booking__ds__day) +) subq_29 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 6cc7df6c9f..0e046bbbe6 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 @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_5_days_ago + subq_7.metric_time__day + , subq_7.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,11 +123,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +346,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 -) subq_7 + subq_6.metric_time__day + ) subq_7 +) subq_8 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 4a3f73badc..039c786eba 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 @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , SUM(subq_9.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_11 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_10.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) +) subq_17 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 9c0bdbd42b..fa4feee8f6 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 @@ -4,55 +4,77 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_15.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once'] SELECT - subq_12.metric_time__day - , subq_12.bookings_offset_once + subq_14.metric_time__day + , subq_14.bookings_offset_once FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.booking__is_instant - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.booking__is_instant + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.booking__is_instant AS booking__is_instant - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.booking__is_instant AS booking__is_instant + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant + subq_8.metric_time__day + , subq_8.booking__is_instant , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.booking__is_instant - , subq_6.bookings + subq_7.metric_time__day + , subq_7.booking__is_instant + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.booking__is_instant - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.booking__is_instant - , subq_4.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -132,7 +154,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -155,11 +177,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +400,18 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE booking__is_instant - ) subq_12 -) subq_13 + ) subq_14 +) 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_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 d62752cb4f..f35f435ae7 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 @@ -15,10 +15,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds 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 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_25.booking__is_instant AS booking__is_instant + , subq_25.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +31,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds 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 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , SUM(subq_17.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,16 +43,16 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_17 ON - subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day - ) subq_25 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_25.metric_time__day + ) subq_29 WHERE booking__is_instant -) subq_27 +) subq_31 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 968a86830c..26868d8854 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 @@ -4,25 +4,47 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , MAX(subq_8.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_14.booking_fees) AS booking_fees + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_15.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_5.booking_fees_start_of_month AS booking_fees_start_of_month FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_6 + ) subq_7 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +267,129 @@ FROM ( ) subq_4 ) subq_5 ON - DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day - ) subq_8 + DATE_TRUNC('month', subq_8.metric_time__day) = subq_5.metric_time__day + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , booking_value * 0.05 AS booking_fees FROM ( -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , subq_12.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_11.metric_time__day - , SUM(subq_11.booking_value) AS booking_value + subq_12.metric_time__day + , SUM(subq_12.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_11.metric_time__day + , subq_11.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.ds_partitioned__day - , subq_9.ds_partitioned__week - , subq_9.ds_partitioned__month - , subq_9.ds_partitioned__quarter - , subq_9.ds_partitioned__year - , subq_9.ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy - , subq_9.paid_at__day - , subq_9.paid_at__week - , subq_9.paid_at__month - , subq_9.paid_at__quarter - , subq_9.paid_at__year - , subq_9.paid_at__extract_year - , subq_9.paid_at__extract_quarter - , subq_9.paid_at__extract_month - , subq_9.paid_at__extract_day - , subq_9.paid_at__extract_dow - , subq_9.paid_at__extract_doy - , subq_9.booking__ds__day - , subq_9.booking__ds__week - , subq_9.booking__ds__month - , subq_9.booking__ds__quarter - , subq_9.booking__ds__year - , subq_9.booking__ds__extract_year - , subq_9.booking__ds__extract_quarter - , subq_9.booking__ds__extract_month - , subq_9.booking__ds__extract_day - , subq_9.booking__ds__extract_dow - , subq_9.booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day - , subq_9.booking__paid_at__week - , subq_9.booking__paid_at__month - , subq_9.booking__paid_at__quarter - , subq_9.booking__paid_at__year - , subq_9.booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy - , subq_9.ds__day AS metric_time__day - , subq_9.ds__week AS metric_time__week - , subq_9.ds__month AS metric_time__month - , subq_9.ds__quarter AS metric_time__quarter - , subq_9.ds__year AS metric_time__year - , subq_9.ds__extract_year AS metric_time__extract_year - , subq_9.ds__extract_quarter AS metric_time__extract_quarter - , subq_9.ds__extract_month AS metric_time__extract_month - , subq_9.ds__extract_day AS metric_time__extract_day - , subq_9.ds__extract_dow AS metric_time__extract_dow - , subq_9.ds__extract_doy AS metric_time__extract_doy - , subq_9.listing - , subq_9.guest - , subq_9.host - , subq_9.booking__listing - , subq_9.booking__guest - , subq_9.booking__host - , subq_9.is_instant - , subq_9.booking__is_instant - , subq_9.bookings - , subq_9.instant_bookings - , subq_9.booking_value - , subq_9.max_booking_value - , subq_9.min_booking_value - , subq_9.bookers - , subq_9.average_booking_value - , subq_9.referred_bookings - , subq_9.median_booking_value - , subq_9.booking_value_p99 - , subq_9.discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -460,16 +482,16 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_11.metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ) subq_15 ON - subq_8.metric_time__day = subq_14.metric_time__day + subq_9.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) +) subq_16 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 101e623ab7..72c961aeeb 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 @@ -9,15 +9,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_30.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_32.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day - , subq_21.booking_fees_start_of_month AS booking_fees_start_of_month - FROM ***************************.mf_time_spine subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_22.booking_fees_start_of_month AS booking_fees_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -35,11 +35,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_20 - ) subq_21 + ) subq_21 + ) subq_22 ON - DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_22.metric_time__day + ) subq_26 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -57,10 +57,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_29 - ) subq_30 + ) subq_31 + ) subq_32 ON - subq_24.metric_time__day = subq_30.metric_time__day + subq_26.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_26.metric_time__day, subq_32.metric_time__day) +) subq_33 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 b3f4befad2..90ee7dc5b3 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 @@ -4,39 +4,61 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_13.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -116,7 +138,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -139,11 +161,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +384,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day -) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day +) subq_13 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 ec796be86d..7b5122abe0 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day - , subq_20.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_23.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +23,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_15.ds AS metric_time__day - , SUM(subq_13.bookings) AS bookings - FROM ***************************.mf_time_spine subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_15.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -33,13 +33,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_15 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_22 + ) subq_23 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_23.metric_time__day +) subq_27 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 a719769718..31148bb43d 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 @@ -4,44 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -121,7 +143,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -144,11 +166,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +389,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 + WHERE subq_13.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' +) subq_14 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 457a8a18d9..e968ba5c32 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,9 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +24,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -34,14 +34,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_24.metric_time__day + WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 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 1645b05276..b514f20125 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 @@ -4,44 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -121,7 +143,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -144,11 +166,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +389,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_12 +) subq_14 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 5d979eb0ce..dede1c8e9b 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 @@ -14,9 +14,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +28,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -38,15 +38,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - ) subq_24 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 2 day = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_25 +) subq_29 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 470dd41cc3..9df60eefbb 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 @@ -6,124 +6,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month + subq_9.metric_time__month , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.bookings AS bookings_start_of_month + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.bookings + subq_6.metric_time__month + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__month + , subq_5.metric_time__day + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -202,8 +202,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -226,12 +226,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__month + , subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day AS metric_time__day + , subq_2.ds__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +452,13 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE subq_2.metric_time__month = subq_2.metric_time__day - ) subq_4 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + WHERE subq_4.metric_time__month = subq_4.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 -) subq_8 + subq_7.metric_time__month + ) subq_8 +) subq_9 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 29518080d5..755771b698 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 @@ -19,10 +19,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , DATE_TRUNC('month', subq_12.ds) AS metric_time__month - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -30,12 +30,12 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_TRUNC('month', subq_12.ds) = subq_10.metric_time__day - WHERE DATE_TRUNC('month', subq_12.ds) = subq_12.ds - ) subq_13 + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_15 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month -) subq_17 +) subq_19 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 e89f0ed249..fd2b0d01a9 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 @@ -6,31 +6,31 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.metric_time__month - , subq_7.metric_time__year + subq_8.metric_time__day + , subq_8.metric_time__month + , subq_8.metric_time__year , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.bookings AS bookings_start_of_month + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -108,9 +108,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -133,13 +133,39 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__month', 'metric_time__year', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__month + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +362,12 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 -) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 +) subq_8 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 d92697dcfc..ae1675bc44 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 @@ -16,11 +16,11 @@ 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 - , SUM(subq_9.bookings) AS bookings_start_of_month - FROM ***************************.mf_time_spine subq_11 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_10.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,11 +28,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_10.metric_time__day GROUP BY - subq_11.ds - , DATE_TRUNC('month', subq_11.ds) - , DATE_TRUNC('year', subq_11.ds) -) subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) + , DATE_TRUNC('month', time_spine_src_28006.ds) + , DATE_TRUNC('year', time_spine_src_28006.ds) +) subq_17 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 a9a36007ac..3de46500ff 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.booking__ds__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS booking__ds__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.booking__ds__day) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 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 8fadab17b1..75a885dace 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY booking__ds__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS booking__ds__day + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.booking__ds__day + DATE_TRUNC('month', DATE_TRUNC('day', time_spine_src_28006.ds)) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_19.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) +) subq_29 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 547e6fe97f..c7c4b05767 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 @@ -6,130 +6,130 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__month + subq_16.metric_time__month , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) AS metric_time__month - , MAX(subq_8.booking_value) AS booking_value - , MAX(subq_14.bookers) AS bookers + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_15.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.booking_value + subq_8.metric_time__month + , subq_8.booking_value FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.booking_value) AS booking_value + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.booking_value + subq_6.metric_time__month + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__month + , subq_5.metric_time__day + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -208,8 +208,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -232,12 +232,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__month + , subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day AS metric_time__day + , subq_2.ds__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +458,232 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 - ) subq_8 + subq_7.metric_time__month + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__month - , subq_13.bookers + subq_14.metric_time__month + , subq_14.bookers FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__month - , COUNT(DISTINCT subq_12.bookers) AS bookers + subq_13.metric_time__month + , COUNT(DISTINCT subq_13.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__month'] SELECT - subq_11.metric_time__month - , subq_11.bookers + subq_12.metric_time__month + , subq_12.bookers FROM ( -- Constrain Output with WHERE SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__day - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__day + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Metric Time Dimension 'ds' SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.ds_partitioned__day - , subq_9.ds_partitioned__week - , subq_9.ds_partitioned__month - , subq_9.ds_partitioned__quarter - , subq_9.ds_partitioned__year - , subq_9.ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy - , subq_9.paid_at__day - , subq_9.paid_at__week - , subq_9.paid_at__month - , subq_9.paid_at__quarter - , subq_9.paid_at__year - , subq_9.paid_at__extract_year - , subq_9.paid_at__extract_quarter - , subq_9.paid_at__extract_month - , subq_9.paid_at__extract_day - , subq_9.paid_at__extract_dow - , subq_9.paid_at__extract_doy - , subq_9.booking__ds__day - , subq_9.booking__ds__week - , subq_9.booking__ds__month - , subq_9.booking__ds__quarter - , subq_9.booking__ds__year - , subq_9.booking__ds__extract_year - , subq_9.booking__ds__extract_quarter - , subq_9.booking__ds__extract_month - , subq_9.booking__ds__extract_day - , subq_9.booking__ds__extract_dow - , subq_9.booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day - , subq_9.booking__paid_at__week - , subq_9.booking__paid_at__month - , subq_9.booking__paid_at__quarter - , subq_9.booking__paid_at__year - , subq_9.booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy - , subq_9.ds__day AS metric_time__day - , subq_9.ds__week AS metric_time__week - , subq_9.ds__month AS metric_time__month - , subq_9.ds__quarter AS metric_time__quarter - , subq_9.ds__year AS metric_time__year - , subq_9.ds__extract_year AS metric_time__extract_year - , subq_9.ds__extract_quarter AS metric_time__extract_quarter - , subq_9.ds__extract_month AS metric_time__extract_month - , subq_9.ds__extract_day AS metric_time__extract_day - , subq_9.ds__extract_dow AS metric_time__extract_dow - , subq_9.ds__extract_doy AS metric_time__extract_doy - , subq_9.listing - , subq_9.guest - , subq_9.host - , subq_9.booking__listing - , subq_9.booking__guest - , subq_9.booking__host - , subq_9.is_instant - , subq_9.booking__is_instant - , subq_9.bookings - , subq_9.instant_bookings - , subq_9.booking_value - , subq_9.max_booking_value - , subq_9.min_booking_value - , subq_9.bookers - , subq_9.average_booking_value - , subq_9.referred_bookings - , subq_9.median_booking_value - , subq_9.booking_value_p99 - , subq_9.discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -752,17 +776,17 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 + ) subq_10 + ) subq_11 WHERE metric_time__day = '2020-01-01' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__month - ) subq_13 - ) subq_14 + subq_13.metric_time__month + ) subq_14 + ) subq_15 ON - subq_8.metric_time__month = subq_14.metric_time__month + subq_9.metric_time__month = subq_15.metric_time__month GROUP BY - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) -) subq_15 + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) +) subq_16 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 63f543a976..9c111b5bc8 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 @@ -11,9 +11,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_30.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_30.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_32.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_32.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -25,19 +25,19 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_19.ds AS metric_time__day - , DATE_TRUNC('month', subq_19.ds) AS metric_time__month + DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day , bookings_source_src_28000.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_19.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_22 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_24 + ) subq_26 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookers', 'metric_time__month'] @@ -54,13 +54,13 @@ FROM ( , DATE_TRUNC('month', ds) AS metric_time__month , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_28 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_30 + ) subq_32 ON - subq_24.metric_time__month = subq_30.metric_time__month + subq_26.metric_time__month = subq_32.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_30.metric_time__month) -) subq_31 + COALESCE(subq_26.metric_time__month, subq_32.metric_time__month) +) subq_33 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 3b4a0a5883..20daf1442e 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 @@ -6,39 +6,39 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.metric_time__month - , subq_13.metric_time__year + subq_14.metric_time__day + , subq_14.metric_time__month + , subq_14.metric_time__year , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) AS metric_time__month + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) AS metric_time__year + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.booking_value + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.booking_value) AS booking_value + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.booking_value + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -116,9 +116,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -141,13 +141,39 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__month', 'metric_time__year', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__month + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +370,137 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.metric_time__month - , subq_11.metric_time__year - , subq_11.bookers + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.metric_time__year + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_9.metric_time__day - , subq_9.metric_time__month - , subq_9.metric_time__year - , subq_9.bookers + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -567,25 +593,25 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - ) subq_11 - ) subq_12 + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + ) subq_12 + ) subq_13 ON ( - subq_7.metric_time__day = subq_12.metric_time__day + subq_8.metric_time__day = subq_13.metric_time__day ) AND ( - subq_7.metric_time__month = subq_12.metric_time__month + subq_8.metric_time__month = subq_13.metric_time__month ) AND ( - subq_7.metric_time__year = subq_12.metric_time__year + subq_8.metric_time__year = subq_13.metric_time__year ) GROUP BY - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) -) subq_13 + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) +) subq_14 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 0c93f04252..a53bd95dec 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 @@ -13,31 +13,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_28.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_28.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_28.bookers) AS bookers FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] -- 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 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_TRUNC('day', time_spine_src_28006.ds) - 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_21 + DATE_TRUNC('day', time_spine_src_28006.ds) + , DATE_TRUNC('month', time_spine_src_28006.ds) + , DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -54,17 +54,17 @@ FROM ( DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) , DATE_TRUNC('year', ds) - ) subq_26 + ) subq_28 ON ( - subq_21.metric_time__day = subq_26.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day ) AND ( - subq_21.metric_time__month = subq_26.metric_time__month + subq_23.metric_time__month = subq_28.metric_time__month ) AND ( - subq_21.metric_time__year = subq_26.metric_time__year + subq_23.metric_time__year = subq_28.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) -) subq_27 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_28.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_28.metric_time__year) +) subq_29 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 6c2e29f3af..9d923a5c20 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.booking__ds__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS booking__ds__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + subq_9.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 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 84c0c9aea0..fe5d694eb8 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY booking__ds__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS booking__ds__day + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.booking__ds__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_19.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) +) subq_29 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 8ab0d9ab99..5d70ba04fe 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 @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day + subq_9.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.bookings AS bookings_5_days_ago + subq_8.metric_time__day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__day - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_4.metric_time__day - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__month - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__month + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -224,11 +224,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +447,12 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - WHERE subq_4.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_5 - ) subq_6 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__day - ) subq_7 -) subq_8 + subq_7.metric_time__day + ) subq_8 +) subq_9 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 9e6a52124f..0a2fcd5c9c 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,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,10 +23,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 5 day = subq_11.metric_time__day + WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + DATE_TRUNC('day', time_spine_src_28006.ds) +) subq_19 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 bde8e65927..511a549211 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 @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.metric_time__day AS metric_time__day + subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_5.metric_time__day ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day -) subq_9 + subq_9.metric_time__day = subq_6.metric_time__day +) subq_10 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 1f7ba0288a..d02735684e 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 @@ -9,28 +9,28 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_18.ds AS metric_time__day - , subq_16.bookers AS bookers - FROM ***************************.mf_time_spine subq_18 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_17.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 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_14.ds AS metric_time__day , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_14 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_14.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_17.metric_time__day +) subq_21 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 b9c24f20ae..c79cb0f787 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 @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_7.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_8.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_17.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +260,254 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 - ) subq_7 + subq_6.metric_time__day = subq_3.metric_time__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_2_weeks_ago + subq_16.metric_time__day + , subq_16.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__day + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_14.metric_time__day + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__year AS metric_time__year - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__year AS metric_time__year + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__day AS metric_time__day + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -556,18 +600,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 14 day = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 14 day = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 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 31ebdbb9f8..9109c16595 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_24.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_27.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_36.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -20,9 +20,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day - , subq_20.bookings AS bookings - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_22.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,23 +36,23 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_19 + ) subq_21 GROUP BY metric_time__day - ) subq_20 + ) subq_22 ON - subq_22.ds = subq_20.metric_time__day - ) subq_23 - ) subq_24 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_22.metric_time__day + ) subq_26 + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_28 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , SUM(subq_29.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -60,14 +60,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 14 day = subq_26.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + DATE_TRUNC('day', time_spine_src_28006.ds) + ) subq_36 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_27.metric_time__day = subq_36.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) +) subq_37 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index cc87f575c1..9ad3d83ade 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (metric_time__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - metric_time__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 83cb6095ed..da820c3bdd 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns 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_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - metric_time__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (metric_time__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (metric_time__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 0c1226247f..b33427eadb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.booking__ds__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.booking__ds__day AS booking__ds__day + subq_8.booking__ds__day AS booking__ds__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['booking__ds__day',] SELECT subq_7.booking__ds__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS booking__ds__day - , subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS booking__ds__day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -342,5 +365,5 @@ FROM ( subq_3.booking__ds__day ) subq_4 ON - subq_5.booking__ds__day = subq_4.booking__ds__day -) subq_8 + subq_8.booking__ds__day = subq_4.booking__ds__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index bbcf6bed72..ba8466e77c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.booking__ds__day AS booking__ds__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.booking__ds__day AS booking__ds__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking__ds__day',] SELECT booking__ds__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT - ds AS booking__ds__day - , ds AS metric_time__day + DATE_TRUNC('day', ds) AS booking__ds__day + , DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY booking__ds__day -) subq_13 +) subq_14 ON - subq_14.booking__ds__day = subq_13.booking__ds__day + subq_18.booking__ds__day = subq_14.booking__ds__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 6387b7c078..4ff92475aa 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 56ac283876..e3a970ac36 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT - ds AS metric_time__day + DATE_TRUNC('day', ds) AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 11529a53fb..af7fe9e2d3 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.archived_users AS archived_users_join_to_time_spine + subq_9.metric_time__day + , subq_9.archived_users AS archived_users_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.archived_users AS archived_users FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', subq_6.ts) AS metric_time__day - , subq_6.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_6 + subq_6.ts__hour + , subq_6.ts__day + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__hour + , subq_5.ts__day + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_5 + ) subq_6 + WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') ) subq_7 - WHERE ( - metric_time__hour > '2020-01-01 00:09:00' - ) AND ( - metric_time__day = '2020-01-01' - ) GROUP BY subq_7.metric_time__day - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -618,5 +640,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 64e5073c79..413be42cc7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.archived_users AS archived_users_join_to_time_spine + subq_18.metric_time__day AS metric_time__day + , subq_14.archived_users AS archived_users_join_to_time_spine FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Transform Time Dimension Columns SELECT DATE_TRUNC('day', ts) AS metric_time__day - , ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + , DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour time_spine_src_28005 ) subq_16 - WHERE ( - metric_time__hour > '2020-01-01 00:09:00' - ) AND ( - metric_time__day = '2020-01-01' - ) + WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['archived_users', 'metric_time__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', archived_at) AS metric_time__day , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_10 + ) subq_11 WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.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 3661b1e49d..7b95ea1841 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 @@ -4,32 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_11.metric_time__day + , subq_11.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_10.metric_time__day AS metric_time__day , subq_5.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.metric_time__day + subq_9.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.ds AS metric_time__day - , DATE_TRUNC('week', subq_7.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_7 - WHERE subq_7.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_8 - WHERE metric_time__week > '2020-01-01' - ) subq_6 + subq_8.ds__day + , subq_8.ds__week + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__day + , subq_6.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_6 + ) subq_7 + WHERE metric_time__week > '2020-01-01' + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_9 + ) subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -446,7 +480,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ON - subq_6.metric_time__day = subq_5.metric_time__day - ) subq_9 - WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_10 + subq_10.metric_time__day = subq_5.metric_time__day + ) subq_11 + WHERE subq_11.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_12 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 289c4bd7a9..ba5ecfb1fc 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 @@ -10,22 +10,28 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.bookings AS bookings + subq_23.metric_time__day AS metric_time__day + , subq_18.bookings AS bookings FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns 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_18 - WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_19 - WHERE metric_time__week > '2020-01-01' - ) subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_20 + WHERE ( + metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) AND ( + metric_time__week > '2020-01-01' + ) + ) subq_23 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -43,12 +49,12 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_13 + ) subq_15 WHERE metric_time__week > '2020-01-01' GROUP BY metric_time__day - ) subq_16 + ) subq_18 ON - subq_17.metric_time__day = subq_16.metric_time__day - WHERE subq_17.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_21 + subq_23.metric_time__day = subq_18.metric_time__day + WHERE subq_23.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_25 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 2aa9af4a15..ee8df1a2da 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 @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +249,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 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 30f3bf383d..2266f176e6 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -25,10 +25,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day - ) subq_10 + ) subq_11 ON - subq_12.ds = subq_10.metric_time__day -) subq_13 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.metric_time__day +) subq_15 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql index 4263d4c10c..5c80aeb669 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__month + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__month AS metric_time__month + subq_6.metric_time__month AS metric_time__month , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month',] SELECT - DATE_TRUNC('month', subq_5.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_5 + subq_5.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 GROUP BY - DATE_TRUNC('month', subq_5.ds) - ) subq_4 + subq_5.metric_time__month + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -229,5 +251,5 @@ FROM ( subq_2.metric_time__month ) subq_3 ON - subq_4.metric_time__month = subq_3.metric_time__month -) subq_6 + subq_6.metric_time__month = subq_3.metric_time__month +) subq_7 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 2eaeedf472..0f6d1ad416 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql @@ -9,16 +9,18 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_11.metric_time__month AS metric_time__month - , subq_10.bookings AS bookings + subq_14.metric_time__month AS metric_time__month + , subq_11.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__month',] SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY DATE_TRUNC('month', ds) - ) subq_11 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,10 +34,10 @@ FROM ( DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__month - ) subq_10 + ) subq_11 ON - subq_11.metric_time__month = subq_10.metric_time__month -) subq_13 + subq_14.metric_time__month = subq_11.metric_time__month +) subq_15 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 95501d3106..6756fb68e3 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 @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__extract_dow + subq_14.metric_time__extract_dow , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) AS metric_time__extract_dow + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) AS metric_time__extract_dow , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__extract_dow - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__extract_dow + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__extract_dow - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__extract_dow + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] SELECT - subq_9.metric_time__extract_dow - , subq_9.bookings + subq_10.metric_time__extract_dow + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_month AS metric_time__extract_month , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__extract_dow AS metric_time__extract_dow + , subq_9.metric_time__extract_dow AS metric_time__extract_dow + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__extract_dow', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - , EXTRACT(isodow FROM subq_8.ds) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__extract_dow + , subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day AS metric_time__day + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +570,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__extract_dow - ) subq_11 - ) subq_12 + subq_11.metric_time__extract_dow + ) subq_12 + ) subq_13 ON - subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + subq_4.metric_time__extract_dow = subq_13.metric_time__extract_dow GROUP BY - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) -) subq_13 + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) +) subq_14 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 475bffcecf..db8b28f051 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 @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_28.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( EXTRACT(isodow FROM ds) AS metric_time__extract_dow , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__extract_dow - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - EXTRACT(isodow FROM subq_22.ds) AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + EXTRACT(isodow FROM time_spine_src_28006.ds) AS metric_time__extract_dow + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_22.ds) - ) subq_26 + EXTRACT(isodow FROM time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_28.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) -) subq_27 + COALESCE(subq_19.metric_time__extract_dow, subq_28.metric_time__extract_dow) +) subq_29 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 ea985a35da..a7fb1cf470 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 @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -410,5 +432,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 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 cb9fd532c0..73167104ba 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 @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + DATE_TRUNC('hour', time_spine_src_28005.ts) AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + DATE_TRUNC('hour', time_spine_src_28005.ts) = subq_11.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 8acb3f0a5d..3a30287e74 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 @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -410,5 +432,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 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 de002a8a69..dff65fd22a 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 @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + DATE_TRUNC('hour', time_spine_src_28005.ts) AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + DATE_TRUNC('hour', time_spine_src_28005.ts) = subq_11.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 80237f2657..f574f478cc 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 @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_grain_to_date_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,39 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__hour AS metric_time__hour + , subq_4.metric_time__hour AS metric_time__hour , subq_1.user AS user , subq_1.home_state AS home_state , subq_1.user__home_state AS user__home_state , subq_1.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour', 'metric_time__hour'] SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 + subq_3.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'archived_at' SELECT @@ -599,10 +621,10 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('hour', subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_TRUNC('hour', subq_4.metric_time__hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 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 a13ee4f4ce..a46faaae38 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 @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + DATE_TRUNC('hour', time_spine_src_28005.ts) AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('hour', subq_11.ts) = subq_9.metric_time__hour + DATE_TRUNC('hour', DATE_TRUNC('hour', time_spine_src_28005.ts)) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + DATE_TRUNC('hour', time_spine_src_28005.ts) +) subq_17 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 5caa97f29e..8f286de7d0 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 @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_window_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,39 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__hour AS metric_time__hour + , subq_4.metric_time__hour AS metric_time__hour , subq_1.user AS user , subq_1.home_state AS home_state , subq_1.user__home_state AS user__home_state , subq_1.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour', 'metric_time__hour'] SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 + subq_3.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'archived_at' SELECT @@ -599,10 +621,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + subq_4.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 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 78923e04e6..405a72f5a6 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 @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + DATE_TRUNC('hour', time_spine_src_28005.ts) AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ts - INTERVAL 1 hour = subq_9.metric_time__hour + DATE_TRUNC('hour', time_spine_src_28005.ts) - INTERVAL 1 hour = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + DATE_TRUNC('hour', time_spine_src_28005.ts) +) subq_17 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 73bd49f0a0..9cea3ca056 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 @@ -4,25 +4,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__hour - , subq_8.archived_users AS subdaily_join_to_time_spine_metric + subq_10.metric_time__hour + , subq_10.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] SELECT - subq_7.metric_time__hour - , subq_7.archived_users + subq_9.metric_time__hour + , subq_9.archived_users FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__hour AS metric_time__hour + subq_8.metric_time__hour AS metric_time__hour , subq_4.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - 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' - ) subq_5 + subq_7.metric_time__hour + FROM ( + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + SELECT + subq_6.ts__hour + , subq_6.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + DATE_TRUNC('hour', time_spine_src_28005.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + ) subq_7 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -611,7 +639,7 @@ FROM ( subq_3.metric_time__hour ) subq_4 ON - subq_5.metric_time__hour = subq_4.metric_time__hour - ) subq_7 - WHERE subq_7.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_8 + subq_8.metric_time__hour = subq_4.metric_time__hour + ) subq_9 + WHERE subq_9.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' +) subq_10 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 c12dd7b5eb..cf6f28b1b1 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 @@ -6,15 +6,18 @@ sql_engine: DuckDB -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] -- Compute Metrics via Expressions SELECT - subq_14.metric_time__hour AS metric_time__hour - , subq_13.archived_users AS subdaily_join_to_time_spine_metric + subq_19.metric_time__hour AS metric_time__hour + , subq_15.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Transform Time Dimension Columns + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + -- Pass Only Elements: ['metric_time__hour',] SELECT - 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' -) subq_14 + DATE_TRUNC('hour', ts) AS metric_time__hour + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + WHERE DATE_TRUNC('hour', ts) BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' +) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -30,10 +33,10 @@ LEFT OUTER JOIN ( , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 WHERE DATE_TRUNC('hour', archived_at) BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' - ) subq_12 + ) subq_14 GROUP BY metric_time__hour -) subq_13 +) subq_15 ON - subq_14.metric_time__hour = subq_13.metric_time__hour -WHERE subq_14.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + subq_19.metric_time__hour = subq_15.metric_time__hour +WHERE subq_19.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' 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 3155d70d46..c170a314ba 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 @@ -128,6 +128,11 @@ docstring: + + + + + @@ -296,6 +301,11 @@ docstring: + + + + + @@ -303,7 +313,7 @@ docstring: - + @@ -361,9 +371,9 @@ docstring: - + - + @@ -380,6 +390,14 @@ docstring: + + + + + + + + @@ -396,7 +414,7 @@ docstring: - + 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 b18699c1ef..80622c0cf4 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 @@ -128,6 +128,11 @@ docstring: + + + + + @@ -135,7 +140,7 @@ docstring: - + @@ -151,9 +156,9 @@ docstring: - + - + @@ -212,7 +217,7 @@ docstring: - + @@ -295,6 +300,11 @@ docstring: + + + + + @@ -302,7 +312,7 @@ docstring: - + @@ -360,9 +370,9 @@ docstring: - + - + @@ -379,6 +389,14 @@ docstring: + + + + + + + + @@ -395,7 +413,7 @@ docstring: - + 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 00cb1d56f1..23fbea8f61 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 @@ -177,6 +177,11 @@ docstring: + + + + + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -502,7 +520,7 @@ docstring: - + 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 4a805d22fc..caa0a36191 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 @@ -177,6 +177,11 @@ docstring: + + + + + @@ -185,7 +190,7 @@ docstring: - + @@ -206,9 +211,9 @@ docstring: - + - + @@ -268,7 +273,7 @@ docstring: - + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -502,7 +520,7 @@ docstring: - + 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 9f0b5af2d3..d3d1313780 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 @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + 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 3d4c78b8dc..ed7e2148c5 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 @@ -125,7 +125,7 @@ docstring: - + @@ -141,9 +141,9 @@ docstring: - + - + @@ -202,7 +202,7 @@ docstring: - + @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + 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 5b4e43f971..b028734ddc 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 @@ -8,34 +8,56 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_29.metric_time__day - , subq_29.listing__country_latest + subq_32.metric_time__day + , subq_32.listing__country_latest , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_12.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_28.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_13.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_31.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.listing__country_latest - , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , subq_12.listing__country_latest + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day + subq_11.metric_time__day AS metric_time__day , subq_8.listing__country_latest AS listing__country_latest , subq_8.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_10.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_9.ds__day AS metric_time__day + , subq_9.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +618,495 @@ FROM ( , subq_7.listing__country_latest ) subq_8 ON - subq_9.metric_time__day = subq_8.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day = subq_8.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_27.metric_time__day - , subq_27.listing__country_latest - , COALESCE(subq_27.bookings, 0) AS bookings_2_weeks_ago + subq_30.metric_time__day + , subq_30.listing__country_latest + , COALESCE(subq_30.bookings, 0) AS bookings_2_weeks_ago FROM ( -- Join to Time Spine Dataset SELECT - subq_25.metric_time__day AS metric_time__day - , subq_24.listing__country_latest AS listing__country_latest - , subq_24.bookings AS bookings + subq_29.metric_time__day AS metric_time__day + , subq_26.listing__country_latest AS listing__country_latest + , subq_26.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_26.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_26 - ) subq_25 + subq_28.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_27 + ) subq_28 + ) subq_29 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest - , SUM(subq_23.bookings) AS bookings + subq_25.metric_time__day + , subq_25.listing__country_latest + , SUM(subq_25.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_22.metric_time__day - , subq_22.listing__country_latest - , subq_22.bookings + subq_24.metric_time__day + , subq_24.listing__country_latest + , subq_24.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_21.metric_time__day - , subq_21.ds__day - , subq_21.ds__week - , subq_21.ds__month - , subq_21.ds__quarter - , subq_21.ds__year - , subq_21.ds__extract_year - , subq_21.ds__extract_quarter - , subq_21.ds__extract_month - , subq_21.ds__extract_day - , subq_21.ds__extract_dow - , subq_21.ds__extract_doy - , subq_21.ds_partitioned__day - , subq_21.ds_partitioned__week - , subq_21.ds_partitioned__month - , subq_21.ds_partitioned__quarter - , subq_21.ds_partitioned__year - , subq_21.ds_partitioned__extract_year - , subq_21.ds_partitioned__extract_quarter - , subq_21.ds_partitioned__extract_month - , subq_21.ds_partitioned__extract_day - , subq_21.ds_partitioned__extract_dow - , subq_21.ds_partitioned__extract_doy - , subq_21.paid_at__day - , subq_21.paid_at__week - , subq_21.paid_at__month - , subq_21.paid_at__quarter - , subq_21.paid_at__year - , subq_21.paid_at__extract_year - , subq_21.paid_at__extract_quarter - , subq_21.paid_at__extract_month - , subq_21.paid_at__extract_day - , subq_21.paid_at__extract_dow - , subq_21.paid_at__extract_doy - , subq_21.booking__ds__day - , subq_21.booking__ds__week - , subq_21.booking__ds__month - , subq_21.booking__ds__quarter - , subq_21.booking__ds__year - , subq_21.booking__ds__extract_year - , subq_21.booking__ds__extract_quarter - , subq_21.booking__ds__extract_month - , subq_21.booking__ds__extract_day - , subq_21.booking__ds__extract_dow - , subq_21.booking__ds__extract_doy - , subq_21.booking__ds_partitioned__day - , subq_21.booking__ds_partitioned__week - , subq_21.booking__ds_partitioned__month - , subq_21.booking__ds_partitioned__quarter - , subq_21.booking__ds_partitioned__year - , subq_21.booking__ds_partitioned__extract_year - , subq_21.booking__ds_partitioned__extract_quarter - , subq_21.booking__ds_partitioned__extract_month - , subq_21.booking__ds_partitioned__extract_day - , subq_21.booking__ds_partitioned__extract_dow - , subq_21.booking__ds_partitioned__extract_doy - , subq_21.booking__paid_at__day - , subq_21.booking__paid_at__week - , subq_21.booking__paid_at__month - , subq_21.booking__paid_at__quarter - , subq_21.booking__paid_at__year - , subq_21.booking__paid_at__extract_year - , subq_21.booking__paid_at__extract_quarter - , subq_21.booking__paid_at__extract_month - , subq_21.booking__paid_at__extract_day - , subq_21.booking__paid_at__extract_dow - , subq_21.booking__paid_at__extract_doy - , subq_21.metric_time__week - , subq_21.metric_time__month - , subq_21.metric_time__quarter - , subq_21.metric_time__year - , subq_21.metric_time__extract_year - , subq_21.metric_time__extract_quarter - , subq_21.metric_time__extract_month - , subq_21.metric_time__extract_day - , subq_21.metric_time__extract_dow - , subq_21.metric_time__extract_doy - , subq_21.listing - , subq_21.guest - , subq_21.host - , subq_21.booking__listing - , subq_21.booking__guest - , subq_21.booking__host - , subq_21.is_instant - , subq_21.booking__is_instant - , subq_21.listing__country_latest - , subq_21.bookings - , subq_21.instant_bookings - , subq_21.booking_value - , subq_21.max_booking_value - , subq_21.min_booking_value - , subq_21.bookers - , subq_21.average_booking_value - , subq_21.referred_bookings - , subq_21.median_booking_value - , subq_21.booking_value_p99 - , subq_21.discrete_booking_value_p99 - , subq_21.approximate_continuous_booking_value_p99 - , subq_21.approximate_discrete_booking_value_p99 + subq_23.ds__day + , subq_23.ds__week + , subq_23.ds__month + , subq_23.ds__quarter + , subq_23.ds__year + , subq_23.ds__extract_year + , subq_23.ds__extract_quarter + , subq_23.ds__extract_month + , subq_23.ds__extract_day + , subq_23.ds__extract_dow + , subq_23.ds__extract_doy + , subq_23.ds_partitioned__day + , subq_23.ds_partitioned__week + , subq_23.ds_partitioned__month + , subq_23.ds_partitioned__quarter + , subq_23.ds_partitioned__year + , subq_23.ds_partitioned__extract_year + , subq_23.ds_partitioned__extract_quarter + , subq_23.ds_partitioned__extract_month + , subq_23.ds_partitioned__extract_day + , subq_23.ds_partitioned__extract_dow + , subq_23.ds_partitioned__extract_doy + , subq_23.paid_at__day + , subq_23.paid_at__week + , subq_23.paid_at__month + , subq_23.paid_at__quarter + , subq_23.paid_at__year + , subq_23.paid_at__extract_year + , subq_23.paid_at__extract_quarter + , subq_23.paid_at__extract_month + , subq_23.paid_at__extract_day + , subq_23.paid_at__extract_dow + , subq_23.paid_at__extract_doy + , subq_23.booking__ds__day + , subq_23.booking__ds__week + , subq_23.booking__ds__month + , subq_23.booking__ds__quarter + , subq_23.booking__ds__year + , subq_23.booking__ds__extract_year + , subq_23.booking__ds__extract_quarter + , subq_23.booking__ds__extract_month + , subq_23.booking__ds__extract_day + , subq_23.booking__ds__extract_dow + , subq_23.booking__ds__extract_doy + , subq_23.booking__ds_partitioned__day + , subq_23.booking__ds_partitioned__week + , subq_23.booking__ds_partitioned__month + , subq_23.booking__ds_partitioned__quarter + , subq_23.booking__ds_partitioned__year + , subq_23.booking__ds_partitioned__extract_year + , subq_23.booking__ds_partitioned__extract_quarter + , subq_23.booking__ds_partitioned__extract_month + , subq_23.booking__ds_partitioned__extract_day + , subq_23.booking__ds_partitioned__extract_dow + , subq_23.booking__ds_partitioned__extract_doy + , subq_23.booking__paid_at__day + , subq_23.booking__paid_at__week + , subq_23.booking__paid_at__month + , subq_23.booking__paid_at__quarter + , subq_23.booking__paid_at__year + , subq_23.booking__paid_at__extract_year + , subq_23.booking__paid_at__extract_quarter + , subq_23.booking__paid_at__extract_month + , subq_23.booking__paid_at__extract_day + , subq_23.booking__paid_at__extract_dow + , subq_23.booking__paid_at__extract_doy + , subq_23.metric_time__week + , subq_23.metric_time__month + , subq_23.metric_time__quarter + , subq_23.metric_time__year + , subq_23.metric_time__extract_year + , subq_23.metric_time__extract_quarter + , subq_23.metric_time__extract_month + , subq_23.metric_time__extract_day + , subq_23.metric_time__extract_dow + , subq_23.metric_time__extract_doy + , subq_23.metric_time__day + , subq_23.listing + , subq_23.guest + , subq_23.host + , subq_23.booking__listing + , subq_23.booking__guest + , subq_23.booking__host + , subq_23.is_instant + , subq_23.booking__is_instant + , subq_23.listing__country_latest + , subq_23.bookings + , subq_23.instant_bookings + , subq_23.booking_value + , subq_23.max_booking_value + , subq_23.min_booking_value + , subq_23.bookers + , subq_23.average_booking_value + , subq_23.referred_bookings + , subq_23.median_booking_value + , subq_23.booking_value_p99 + , subq_23.discrete_booking_value_p99 + , subq_23.approximate_continuous_booking_value_p99 + , subq_23.approximate_discrete_booking_value_p99 FROM ( -- Join Standard Outputs SELECT - subq_20.country_latest AS listing__country_latest - , subq_17.metric_time__day AS metric_time__day - , subq_17.ds__day AS ds__day - , subq_17.ds__week AS ds__week - , subq_17.ds__month AS ds__month - , subq_17.ds__quarter AS ds__quarter - , subq_17.ds__year AS ds__year - , subq_17.ds__extract_year AS ds__extract_year - , subq_17.ds__extract_quarter AS ds__extract_quarter - , subq_17.ds__extract_month AS ds__extract_month - , subq_17.ds__extract_day AS ds__extract_day - , subq_17.ds__extract_dow AS ds__extract_dow - , subq_17.ds__extract_doy AS ds__extract_doy - , subq_17.ds_partitioned__day AS ds_partitioned__day - , subq_17.ds_partitioned__week AS ds_partitioned__week - , subq_17.ds_partitioned__month AS ds_partitioned__month - , subq_17.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_17.ds_partitioned__year AS ds_partitioned__year - , subq_17.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_17.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_17.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_17.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_17.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_17.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_17.paid_at__day AS paid_at__day - , subq_17.paid_at__week AS paid_at__week - , subq_17.paid_at__month AS paid_at__month - , subq_17.paid_at__quarter AS paid_at__quarter - , subq_17.paid_at__year AS paid_at__year - , subq_17.paid_at__extract_year AS paid_at__extract_year - , subq_17.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_17.paid_at__extract_month AS paid_at__extract_month - , subq_17.paid_at__extract_day AS paid_at__extract_day - , subq_17.paid_at__extract_dow AS paid_at__extract_dow - , subq_17.paid_at__extract_doy AS paid_at__extract_doy - , subq_17.booking__ds__day AS booking__ds__day - , subq_17.booking__ds__week AS booking__ds__week - , subq_17.booking__ds__month AS booking__ds__month - , subq_17.booking__ds__quarter AS booking__ds__quarter - , subq_17.booking__ds__year AS booking__ds__year - , subq_17.booking__ds__extract_year AS booking__ds__extract_year - , subq_17.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_17.booking__ds__extract_month AS booking__ds__extract_month - , subq_17.booking__ds__extract_day AS booking__ds__extract_day - , subq_17.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_17.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_17.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_17.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_17.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_17.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_17.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_17.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_17.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_17.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_17.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_17.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_17.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_17.booking__paid_at__day AS booking__paid_at__day - , subq_17.booking__paid_at__week AS booking__paid_at__week - , subq_17.booking__paid_at__month AS booking__paid_at__month - , subq_17.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_17.booking__paid_at__year AS booking__paid_at__year - , subq_17.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_17.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_17.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_17.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_17.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_17.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_17.metric_time__week AS metric_time__week - , subq_17.metric_time__month AS metric_time__month - , subq_17.metric_time__quarter AS metric_time__quarter - , subq_17.metric_time__year AS metric_time__year - , subq_17.metric_time__extract_year AS metric_time__extract_year - , subq_17.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_17.metric_time__extract_month AS metric_time__extract_month - , subq_17.metric_time__extract_day AS metric_time__extract_day - , subq_17.metric_time__extract_dow AS metric_time__extract_dow - , subq_17.metric_time__extract_doy AS metric_time__extract_doy - , subq_17.listing AS listing - , subq_17.guest AS guest - , subq_17.host AS host - , subq_17.booking__listing AS booking__listing - , subq_17.booking__guest AS booking__guest - , subq_17.booking__host AS booking__host - , subq_17.is_instant AS is_instant - , subq_17.booking__is_instant AS booking__is_instant - , subq_17.bookings AS bookings - , subq_17.instant_bookings AS instant_bookings - , subq_17.booking_value AS booking_value - , subq_17.max_booking_value AS max_booking_value - , subq_17.min_booking_value AS min_booking_value - , subq_17.bookers AS bookers - , subq_17.average_booking_value AS average_booking_value - , subq_17.referred_bookings AS referred_bookings - , subq_17.median_booking_value AS median_booking_value - , subq_17.booking_value_p99 AS booking_value_p99 - , subq_17.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_17.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_17.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_22.country_latest AS listing__country_latest + , subq_19.ds__day AS ds__day + , subq_19.ds__week AS ds__week + , subq_19.ds__month AS ds__month + , subq_19.ds__quarter AS ds__quarter + , subq_19.ds__year AS ds__year + , subq_19.ds__extract_year AS ds__extract_year + , subq_19.ds__extract_quarter AS ds__extract_quarter + , subq_19.ds__extract_month AS ds__extract_month + , subq_19.ds__extract_day AS ds__extract_day + , subq_19.ds__extract_dow AS ds__extract_dow + , subq_19.ds__extract_doy AS ds__extract_doy + , subq_19.ds_partitioned__day AS ds_partitioned__day + , subq_19.ds_partitioned__week AS ds_partitioned__week + , subq_19.ds_partitioned__month AS ds_partitioned__month + , subq_19.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_19.ds_partitioned__year AS ds_partitioned__year + , subq_19.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_19.paid_at__day AS paid_at__day + , subq_19.paid_at__week AS paid_at__week + , subq_19.paid_at__month AS paid_at__month + , subq_19.paid_at__quarter AS paid_at__quarter + , subq_19.paid_at__year AS paid_at__year + , subq_19.paid_at__extract_year AS paid_at__extract_year + , subq_19.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_19.paid_at__extract_month AS paid_at__extract_month + , subq_19.paid_at__extract_day AS paid_at__extract_day + , subq_19.paid_at__extract_dow AS paid_at__extract_dow + , subq_19.paid_at__extract_doy AS paid_at__extract_doy + , subq_19.booking__ds__day AS booking__ds__day + , subq_19.booking__ds__week AS booking__ds__week + , subq_19.booking__ds__month AS booking__ds__month + , subq_19.booking__ds__quarter AS booking__ds__quarter + , subq_19.booking__ds__year AS booking__ds__year + , subq_19.booking__ds__extract_year AS booking__ds__extract_year + , subq_19.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_19.booking__ds__extract_month AS booking__ds__extract_month + , subq_19.booking__ds__extract_day AS booking__ds__extract_day + , subq_19.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_19.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day AS booking__paid_at__day + , subq_19.booking__paid_at__week AS booking__paid_at__week + , subq_19.booking__paid_at__month AS booking__paid_at__month + , subq_19.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_19.booking__paid_at__year AS booking__paid_at__year + , subq_19.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_19.metric_time__week AS metric_time__week + , subq_19.metric_time__month AS metric_time__month + , subq_19.metric_time__quarter AS metric_time__quarter + , subq_19.metric_time__year AS metric_time__year + , subq_19.metric_time__extract_year AS metric_time__extract_year + , subq_19.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_19.metric_time__extract_month AS metric_time__extract_month + , subq_19.metric_time__extract_day AS metric_time__extract_day + , subq_19.metric_time__extract_dow AS metric_time__extract_dow + , subq_19.metric_time__extract_doy AS metric_time__extract_doy + , subq_19.metric_time__day AS metric_time__day + , subq_19.listing AS listing + , subq_19.guest AS guest + , subq_19.host AS host + , subq_19.booking__listing AS booking__listing + , subq_19.booking__guest AS booking__guest + , subq_19.booking__host AS booking__host + , subq_19.is_instant AS is_instant + , subq_19.booking__is_instant AS booking__is_instant + , subq_19.bookings AS bookings + , subq_19.instant_bookings AS instant_bookings + , subq_19.booking_value AS booking_value + , subq_19.max_booking_value AS max_booking_value + , subq_19.min_booking_value AS min_booking_value + , subq_19.bookers AS bookers + , subq_19.average_booking_value AS average_booking_value + , subq_19.referred_bookings AS referred_bookings + , subq_19.median_booking_value AS median_booking_value + , subq_19.booking_value_p99 AS booking_value_p99 + , subq_19.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT - subq_14.ds__day AS ds__day - , subq_14.ds__week AS ds__week - , subq_14.ds__month AS ds__month - , subq_14.ds__quarter AS ds__quarter - , subq_14.ds__year AS ds__year - , subq_14.ds__extract_year AS ds__extract_year - , subq_14.ds__extract_quarter AS ds__extract_quarter - , subq_14.ds__extract_month AS ds__extract_month - , subq_14.ds__extract_day AS ds__extract_day - , subq_14.ds__extract_dow AS ds__extract_dow - , subq_14.ds__extract_doy AS ds__extract_doy - , subq_14.ds_partitioned__day AS ds_partitioned__day - , subq_14.ds_partitioned__week AS ds_partitioned__week - , subq_14.ds_partitioned__month AS ds_partitioned__month - , subq_14.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_14.ds_partitioned__year AS ds_partitioned__year - , subq_14.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_14.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_14.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_14.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_14.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_14.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_14.paid_at__day AS paid_at__day - , subq_14.paid_at__week AS paid_at__week - , subq_14.paid_at__month AS paid_at__month - , subq_14.paid_at__quarter AS paid_at__quarter - , subq_14.paid_at__year AS paid_at__year - , subq_14.paid_at__extract_year AS paid_at__extract_year - , subq_14.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_14.paid_at__extract_month AS paid_at__extract_month - , subq_14.paid_at__extract_day AS paid_at__extract_day - , subq_14.paid_at__extract_dow AS paid_at__extract_dow - , subq_14.paid_at__extract_doy AS paid_at__extract_doy - , subq_14.booking__ds__day AS booking__ds__day - , subq_14.booking__ds__week AS booking__ds__week - , subq_14.booking__ds__month AS booking__ds__month - , subq_14.booking__ds__quarter AS booking__ds__quarter - , subq_14.booking__ds__year AS booking__ds__year - , subq_14.booking__ds__extract_year AS booking__ds__extract_year - , subq_14.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_14.booking__ds__extract_month AS booking__ds__extract_month - , subq_14.booking__ds__extract_day AS booking__ds__extract_day - , subq_14.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_14.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_14.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_14.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_14.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_14.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_14.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_14.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_14.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_14.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_14.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_14.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_14.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_14.booking__paid_at__day AS booking__paid_at__day - , subq_14.booking__paid_at__week AS booking__paid_at__week - , subq_14.booking__paid_at__month AS booking__paid_at__month - , subq_14.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_14.booking__paid_at__year AS booking__paid_at__year - , subq_14.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_14.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_14.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_14.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_14.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_14.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_14.metric_time__week AS metric_time__week - , subq_14.metric_time__month AS metric_time__month - , subq_14.metric_time__quarter AS metric_time__quarter - , subq_14.metric_time__year AS metric_time__year - , subq_14.metric_time__extract_year AS metric_time__extract_year - , subq_14.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_14.metric_time__extract_month AS metric_time__extract_month - , subq_14.metric_time__extract_day AS metric_time__extract_day - , subq_14.metric_time__extract_dow AS metric_time__extract_dow - , subq_14.metric_time__extract_doy AS metric_time__extract_doy - , subq_15.metric_time__day AS metric_time__day - , subq_14.listing AS listing - , subq_14.guest AS guest - , subq_14.host AS host - , subq_14.booking__listing AS booking__listing - , subq_14.booking__guest AS booking__guest - , subq_14.booking__host AS booking__host - , subq_14.is_instant AS is_instant - , subq_14.booking__is_instant AS booking__is_instant - , subq_14.bookings AS bookings - , subq_14.instant_bookings AS instant_bookings - , subq_14.booking_value AS booking_value - , subq_14.max_booking_value AS max_booking_value - , subq_14.min_booking_value AS min_booking_value - , subq_14.bookers AS bookers - , subq_14.average_booking_value AS average_booking_value - , subq_14.referred_bookings AS referred_bookings - , subq_14.median_booking_value AS median_booking_value - , subq_14.booking_value_p99 AS booking_value_p99 - , subq_14.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_14.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_14.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_15.ds__day AS ds__day + , subq_15.ds__week AS ds__week + , subq_15.ds__month AS ds__month + , subq_15.ds__quarter AS ds__quarter + , subq_15.ds__year AS ds__year + , subq_15.ds__extract_year AS ds__extract_year + , subq_15.ds__extract_quarter AS ds__extract_quarter + , subq_15.ds__extract_month AS ds__extract_month + , subq_15.ds__extract_day AS ds__extract_day + , subq_15.ds__extract_dow AS ds__extract_dow + , subq_15.ds__extract_doy AS ds__extract_doy + , subq_15.ds_partitioned__day AS ds_partitioned__day + , subq_15.ds_partitioned__week AS ds_partitioned__week + , subq_15.ds_partitioned__month AS ds_partitioned__month + , subq_15.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_15.ds_partitioned__year AS ds_partitioned__year + , subq_15.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_15.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_15.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_15.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_15.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_15.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_15.paid_at__day AS paid_at__day + , subq_15.paid_at__week AS paid_at__week + , subq_15.paid_at__month AS paid_at__month + , subq_15.paid_at__quarter AS paid_at__quarter + , subq_15.paid_at__year AS paid_at__year + , subq_15.paid_at__extract_year AS paid_at__extract_year + , subq_15.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_15.paid_at__extract_month AS paid_at__extract_month + , subq_15.paid_at__extract_day AS paid_at__extract_day + , subq_15.paid_at__extract_dow AS paid_at__extract_dow + , subq_15.paid_at__extract_doy AS paid_at__extract_doy + , subq_15.booking__ds__day AS booking__ds__day + , subq_15.booking__ds__week AS booking__ds__week + , subq_15.booking__ds__month AS booking__ds__month + , subq_15.booking__ds__quarter AS booking__ds__quarter + , subq_15.booking__ds__year AS booking__ds__year + , subq_15.booking__ds__extract_year AS booking__ds__extract_year + , subq_15.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_15.booking__ds__extract_month AS booking__ds__extract_month + , subq_15.booking__ds__extract_day AS booking__ds__extract_day + , subq_15.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_15.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_15.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_15.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_15.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_15.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_15.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_15.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_15.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_15.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_15.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_15.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_15.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_15.booking__paid_at__day AS booking__paid_at__day + , subq_15.booking__paid_at__week AS booking__paid_at__week + , subq_15.booking__paid_at__month AS booking__paid_at__month + , subq_15.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_15.booking__paid_at__year AS booking__paid_at__year + , subq_15.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_15.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_15.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_15.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_15.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_15.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_15.metric_time__week AS metric_time__week + , subq_15.metric_time__month AS metric_time__month + , subq_15.metric_time__quarter AS metric_time__quarter + , subq_15.metric_time__year AS metric_time__year + , subq_15.metric_time__extract_year AS metric_time__extract_year + , subq_15.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_15.metric_time__extract_month AS metric_time__extract_month + , subq_15.metric_time__extract_day AS metric_time__extract_day + , subq_15.metric_time__extract_dow AS metric_time__extract_dow + , subq_15.metric_time__extract_doy AS metric_time__extract_doy + , subq_18.metric_time__day AS metric_time__day + , subq_15.listing AS listing + , subq_15.guest AS guest + , subq_15.host AS host + , subq_15.booking__listing AS booking__listing + , subq_15.booking__guest AS booking__guest + , subq_15.booking__host AS booking__host + , subq_15.is_instant AS is_instant + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings + , subq_15.instant_bookings AS instant_bookings + , subq_15.booking_value AS booking_value + , subq_15.max_booking_value AS max_booking_value + , subq_15.min_booking_value AS min_booking_value + , subq_15.bookers AS bookers + , subq_15.average_booking_value AS average_booking_value + , subq_15.referred_bookings AS referred_bookings + , subq_15.median_booking_value AS median_booking_value + , subq_15.booking_value_p99 AS booking_value_p99 + , subq_15.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_15.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_15.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_16.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_16 - ) subq_15 + subq_17.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_16.ds__day AS metric_time__day + , subq_16.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_16 + ) subq_17 + ) subq_18 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_13.ds__day - , subq_13.ds__week - , subq_13.ds__month - , subq_13.ds__quarter - , subq_13.ds__year - , subq_13.ds__extract_year - , subq_13.ds__extract_quarter - , subq_13.ds__extract_month - , subq_13.ds__extract_day - , subq_13.ds__extract_dow - , subq_13.ds__extract_doy - , subq_13.ds_partitioned__day - , subq_13.ds_partitioned__week - , subq_13.ds_partitioned__month - , subq_13.ds_partitioned__quarter - , subq_13.ds_partitioned__year - , subq_13.ds_partitioned__extract_year - , subq_13.ds_partitioned__extract_quarter - , subq_13.ds_partitioned__extract_month - , subq_13.ds_partitioned__extract_day - , subq_13.ds_partitioned__extract_dow - , subq_13.ds_partitioned__extract_doy - , subq_13.paid_at__day - , subq_13.paid_at__week - , subq_13.paid_at__month - , subq_13.paid_at__quarter - , subq_13.paid_at__year - , subq_13.paid_at__extract_year - , subq_13.paid_at__extract_quarter - , subq_13.paid_at__extract_month - , subq_13.paid_at__extract_day - , subq_13.paid_at__extract_dow - , subq_13.paid_at__extract_doy - , subq_13.booking__ds__day - , subq_13.booking__ds__week - , subq_13.booking__ds__month - , subq_13.booking__ds__quarter - , subq_13.booking__ds__year - , subq_13.booking__ds__extract_year - , subq_13.booking__ds__extract_quarter - , subq_13.booking__ds__extract_month - , subq_13.booking__ds__extract_day - , subq_13.booking__ds__extract_dow - , subq_13.booking__ds__extract_doy - , subq_13.booking__ds_partitioned__day - , subq_13.booking__ds_partitioned__week - , subq_13.booking__ds_partitioned__month - , subq_13.booking__ds_partitioned__quarter - , subq_13.booking__ds_partitioned__year - , subq_13.booking__ds_partitioned__extract_year - , subq_13.booking__ds_partitioned__extract_quarter - , subq_13.booking__ds_partitioned__extract_month - , subq_13.booking__ds_partitioned__extract_day - , subq_13.booking__ds_partitioned__extract_dow - , subq_13.booking__ds_partitioned__extract_doy - , subq_13.booking__paid_at__day - , subq_13.booking__paid_at__week - , subq_13.booking__paid_at__month - , subq_13.booking__paid_at__quarter - , subq_13.booking__paid_at__year - , subq_13.booking__paid_at__extract_year - , subq_13.booking__paid_at__extract_quarter - , subq_13.booking__paid_at__extract_month - , subq_13.booking__paid_at__extract_day - , subq_13.booking__paid_at__extract_dow - , subq_13.booking__paid_at__extract_doy - , subq_13.ds__day AS metric_time__day - , subq_13.ds__week AS metric_time__week - , subq_13.ds__month AS metric_time__month - , subq_13.ds__quarter AS metric_time__quarter - , subq_13.ds__year AS metric_time__year - , subq_13.ds__extract_year AS metric_time__extract_year - , subq_13.ds__extract_quarter AS metric_time__extract_quarter - , subq_13.ds__extract_month AS metric_time__extract_month - , subq_13.ds__extract_day AS metric_time__extract_day - , subq_13.ds__extract_dow AS metric_time__extract_dow - , subq_13.ds__extract_doy AS metric_time__extract_doy - , subq_13.listing - , subq_13.guest - , subq_13.host - , subq_13.booking__listing - , subq_13.booking__guest - , subq_13.booking__host - , subq_13.is_instant - , subq_13.booking__is_instant - , subq_13.bookings - , subq_13.instant_bookings - , subq_13.booking_value - , subq_13.max_booking_value - , subq_13.min_booking_value - , subq_13.bookers - , subq_13.average_booking_value - , subq_13.referred_bookings - , subq_13.median_booking_value - , subq_13.booking_value_p99 - , subq_13.discrete_booking_value_p99 - , subq_13.approximate_continuous_booking_value_p99 - , subq_13.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -1133,86 +1199,86 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 - ) subq_14 + ) subq_14 + ) subq_15 ON - subq_15.metric_time__day - INTERVAL 14 day = subq_14.metric_time__day - ) subq_17 + subq_18.metric_time__day - INTERVAL 14 day = subq_15.metric_time__day + ) subq_19 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_19.listing - , subq_19.country_latest + subq_21.listing + , subq_21.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.created_at__day - , subq_18.created_at__week - , subq_18.created_at__month - , subq_18.created_at__quarter - , subq_18.created_at__year - , subq_18.created_at__extract_year - , subq_18.created_at__extract_quarter - , subq_18.created_at__extract_month - , subq_18.created_at__extract_day - , subq_18.created_at__extract_dow - , subq_18.created_at__extract_doy - , subq_18.listing__ds__day - , subq_18.listing__ds__week - , subq_18.listing__ds__month - , subq_18.listing__ds__quarter - , subq_18.listing__ds__year - , subq_18.listing__ds__extract_year - , subq_18.listing__ds__extract_quarter - , subq_18.listing__ds__extract_month - , subq_18.listing__ds__extract_day - , subq_18.listing__ds__extract_dow - , subq_18.listing__ds__extract_doy - , subq_18.listing__created_at__day - , subq_18.listing__created_at__week - , subq_18.listing__created_at__month - , subq_18.listing__created_at__quarter - , subq_18.listing__created_at__year - , subq_18.listing__created_at__extract_year - , subq_18.listing__created_at__extract_quarter - , subq_18.listing__created_at__extract_month - , subq_18.listing__created_at__extract_day - , subq_18.listing__created_at__extract_dow - , subq_18.listing__created_at__extract_doy - , subq_18.ds__day AS metric_time__day - , subq_18.ds__week AS metric_time__week - , subq_18.ds__month AS metric_time__month - , subq_18.ds__quarter AS metric_time__quarter - , subq_18.ds__year AS metric_time__year - , subq_18.ds__extract_year AS metric_time__extract_year - , subq_18.ds__extract_quarter AS metric_time__extract_quarter - , subq_18.ds__extract_month AS metric_time__extract_month - , subq_18.ds__extract_day AS metric_time__extract_day - , subq_18.ds__extract_dow AS metric_time__extract_dow - , subq_18.ds__extract_doy AS metric_time__extract_doy - , subq_18.listing - , subq_18.user - , subq_18.listing__user - , subq_18.country_latest - , subq_18.is_lux_latest - , subq_18.capacity_latest - , subq_18.listing__country_latest - , subq_18.listing__is_lux_latest - , subq_18.listing__capacity_latest - , subq_18.listings - , subq_18.largest_listing - , subq_18.smallest_listing + subq_20.ds__day + , subq_20.ds__week + , subq_20.ds__month + , subq_20.ds__quarter + , subq_20.ds__year + , subq_20.ds__extract_year + , subq_20.ds__extract_quarter + , subq_20.ds__extract_month + , subq_20.ds__extract_day + , subq_20.ds__extract_dow + , subq_20.ds__extract_doy + , subq_20.created_at__day + , subq_20.created_at__week + , subq_20.created_at__month + , subq_20.created_at__quarter + , subq_20.created_at__year + , subq_20.created_at__extract_year + , subq_20.created_at__extract_quarter + , subq_20.created_at__extract_month + , subq_20.created_at__extract_day + , subq_20.created_at__extract_dow + , subq_20.created_at__extract_doy + , subq_20.listing__ds__day + , subq_20.listing__ds__week + , subq_20.listing__ds__month + , subq_20.listing__ds__quarter + , subq_20.listing__ds__year + , subq_20.listing__ds__extract_year + , subq_20.listing__ds__extract_quarter + , subq_20.listing__ds__extract_month + , subq_20.listing__ds__extract_day + , subq_20.listing__ds__extract_dow + , subq_20.listing__ds__extract_doy + , subq_20.listing__created_at__day + , subq_20.listing__created_at__week + , subq_20.listing__created_at__month + , subq_20.listing__created_at__quarter + , subq_20.listing__created_at__year + , subq_20.listing__created_at__extract_year + , subq_20.listing__created_at__extract_quarter + , subq_20.listing__created_at__extract_month + , subq_20.listing__created_at__extract_day + , subq_20.listing__created_at__extract_dow + , subq_20.listing__created_at__extract_doy + , subq_20.ds__day AS metric_time__day + , subq_20.ds__week AS metric_time__week + , subq_20.ds__month AS metric_time__month + , subq_20.ds__quarter AS metric_time__quarter + , subq_20.ds__year AS metric_time__year + , subq_20.ds__extract_year AS metric_time__extract_year + , subq_20.ds__extract_quarter AS metric_time__extract_quarter + , subq_20.ds__extract_month AS metric_time__extract_month + , subq_20.ds__extract_day AS metric_time__extract_day + , subq_20.ds__extract_dow AS metric_time__extract_dow + , subq_20.ds__extract_doy AS metric_time__extract_doy + , subq_20.listing + , subq_20.user + , subq_20.listing__user + , subq_20.country_latest + , subq_20.is_lux_latest + , subq_20.capacity_latest + , subq_20.listing__country_latest + , subq_20.listing__is_lux_latest + , subq_20.listing__capacity_latest + , subq_20.listings + , subq_20.largest_listing + , subq_20.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1273,30 +1339,30 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_18 - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_17.listing = subq_20.listing - ) subq_21 + subq_19.listing = subq_22.listing + ) subq_23 WHERE booking__is_instant - ) subq_22 - ) subq_23 + ) subq_24 + ) subq_25 GROUP BY - subq_23.metric_time__day - , subq_23.listing__country_latest - ) subq_24 + subq_25.metric_time__day + , subq_25.listing__country_latest + ) subq_26 ON - subq_25.metric_time__day = subq_24.metric_time__day - ) subq_27 - ) subq_28 + subq_29.metric_time__day = subq_26.metric_time__day + ) subq_30 + ) subq_31 ON ( - subq_12.listing__country_latest = subq_28.listing__country_latest + subq_13.listing__country_latest = subq_31.listing__country_latest ) AND ( - subq_12.metric_time__day = subq_28.metric_time__day + subq_13.metric_time__day = subq_31.metric_time__day ) GROUP BY - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) -) subq_29 + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) +) subq_32 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 353a58c7db..a440e5542d 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 @@ -14,10 +14,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_58.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_58.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_42.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_58.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_64.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_64.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_46.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_64.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -27,10 +27,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_40.ds AS metric_time__day - , subq_38.listing__country_latest AS listing__country_latest - , subq_38.bookings AS bookings - FROM ***************************.mf_time_spine subq_40 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_41.listing__country_latest AS listing__country_latest + , subq_41.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -43,9 +43,9 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_31.metric_time__day AS metric_time__day - , subq_31.booking__is_instant AS booking__is_instant - , subq_31.bookings AS bookings + , subq_34.metric_time__day AS metric_time__day + , subq_34.booking__is_instant AS booking__is_instant + , subq_34.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -55,21 +55,21 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_31 + ) subq_34 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_31.listing = listings_latest_src_28000.listing_id - ) subq_35 + subq_34.listing = listings_latest_src_28000.listing_id + ) subq_38 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_38 + ) subq_41 ON - subq_40.ds = subq_38.metric_time__day - ) subq_41 - ) subq_42 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_41.metric_time__day + ) subq_45 + ) subq_46 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -79,10 +79,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_56.ds AS metric_time__day - , subq_54.listing__country_latest AS listing__country_latest - , subq_54.bookings AS bookings - FROM ***************************.mf_time_spine subq_56 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_59.listing__country_latest AS listing__country_latest + , subq_59.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -95,17 +95,17 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_47.metric_time__day AS metric_time__day - , subq_47.booking__is_instant AS booking__is_instant - , subq_47.bookings AS bookings + , subq_52.metric_time__day AS metric_time__day + , subq_52.booking__is_instant AS booking__is_instant + , subq_52.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_46.ds AS metric_time__day - , subq_44.listing AS listing - , subq_44.booking__is_instant AS booking__is_instant - , subq_44.bookings AS bookings - FROM ***************************.mf_time_spine subq_46 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_48.listing AS listing + , subq_48.booking__is_instant AS booking__is_instant + , subq_48.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -115,31 +115,31 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_44 + ) subq_48 ON - subq_46.ds - INTERVAL 14 day = subq_44.metric_time__day - ) subq_47 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_48.metric_time__day + ) subq_52 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_51 + subq_52.listing = listings_latest_src_28000.listing_id + ) subq_56 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_54 + ) subq_59 ON - subq_56.ds = subq_54.metric_time__day - ) subq_57 - ) subq_58 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_59.metric_time__day + ) subq_63 + ) subq_64 ON ( - subq_42.listing__country_latest = subq_58.listing__country_latest + subq_46.listing__country_latest = subq_64.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_58.metric_time__day + subq_46.metric_time__day = subq_64.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_58.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_58.listing__country_latest) -) subq_59 + COALESCE(subq_46.metric_time__day, subq_64.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_64.listing__country_latest) +) subq_65 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 aee6eca8dc..476c46e84e 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 @@ -8,16 +8,16 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest + subq_24.metric_time__day + , subq_24.listing__country_latest , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) AS metric_time__day - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) AS listing__country_latest + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) AS metric_time__day + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) AS listing__country_latest , MAX(subq_9.bookings) AS bookings - , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_23.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -587,225 +587,225 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_21.metric_time__day - , subq_21.listing__country_latest - , subq_21.bookings AS bookings_2_weeks_ago + subq_22.metric_time__day + , subq_22.listing__country_latest + , subq_22.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_20.metric_time__day - , subq_20.listing__country_latest - , SUM(subq_20.bookings) AS bookings + subq_21.metric_time__day + , subq_21.listing__country_latest + , SUM(subq_21.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_19.metric_time__day - , subq_19.listing__country_latest - , subq_19.bookings + subq_20.metric_time__day + , subq_20.listing__country_latest + , subq_20.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_18.metric_time__day - , subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.ds_partitioned__day - , subq_18.ds_partitioned__week - , subq_18.ds_partitioned__month - , subq_18.ds_partitioned__quarter - , subq_18.ds_partitioned__year - , subq_18.ds_partitioned__extract_year - , subq_18.ds_partitioned__extract_quarter - , subq_18.ds_partitioned__extract_month - , subq_18.ds_partitioned__extract_day - , subq_18.ds_partitioned__extract_dow - , subq_18.ds_partitioned__extract_doy - , subq_18.paid_at__day - , subq_18.paid_at__week - , subq_18.paid_at__month - , subq_18.paid_at__quarter - , subq_18.paid_at__year - , subq_18.paid_at__extract_year - , subq_18.paid_at__extract_quarter - , subq_18.paid_at__extract_month - , subq_18.paid_at__extract_day - , subq_18.paid_at__extract_dow - , subq_18.paid_at__extract_doy - , subq_18.booking__ds__day - , subq_18.booking__ds__week - , subq_18.booking__ds__month - , subq_18.booking__ds__quarter - , subq_18.booking__ds__year - , subq_18.booking__ds__extract_year - , subq_18.booking__ds__extract_quarter - , subq_18.booking__ds__extract_month - , subq_18.booking__ds__extract_day - , subq_18.booking__ds__extract_dow - , subq_18.booking__ds__extract_doy - , subq_18.booking__ds_partitioned__day - , subq_18.booking__ds_partitioned__week - , subq_18.booking__ds_partitioned__month - , subq_18.booking__ds_partitioned__quarter - , subq_18.booking__ds_partitioned__year - , subq_18.booking__ds_partitioned__extract_year - , subq_18.booking__ds_partitioned__extract_quarter - , subq_18.booking__ds_partitioned__extract_month - , subq_18.booking__ds_partitioned__extract_day - , subq_18.booking__ds_partitioned__extract_dow - , subq_18.booking__ds_partitioned__extract_doy - , subq_18.booking__paid_at__day - , subq_18.booking__paid_at__week - , subq_18.booking__paid_at__month - , subq_18.booking__paid_at__quarter - , subq_18.booking__paid_at__year - , subq_18.booking__paid_at__extract_year - , subq_18.booking__paid_at__extract_quarter - , subq_18.booking__paid_at__extract_month - , subq_18.booking__paid_at__extract_day - , subq_18.booking__paid_at__extract_dow - , subq_18.booking__paid_at__extract_doy - , subq_18.metric_time__week - , subq_18.metric_time__month - , subq_18.metric_time__quarter - , subq_18.metric_time__year - , subq_18.metric_time__extract_year - , subq_18.metric_time__extract_quarter - , subq_18.metric_time__extract_month - , subq_18.metric_time__extract_day - , subq_18.metric_time__extract_dow - , subq_18.metric_time__extract_doy - , subq_18.listing - , subq_18.guest - , subq_18.host - , subq_18.booking__listing - , subq_18.booking__guest - , subq_18.booking__host - , subq_18.is_instant - , subq_18.booking__is_instant - , subq_18.listing__country_latest - , subq_18.bookings - , subq_18.instant_bookings - , subq_18.booking_value - , subq_18.max_booking_value - , subq_18.min_booking_value - , subq_18.bookers - , subq_18.average_booking_value - , subq_18.referred_bookings - , subq_18.median_booking_value - , subq_18.booking_value_p99 - , subq_18.discrete_booking_value_p99 - , subq_18.approximate_continuous_booking_value_p99 - , subq_18.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.metric_time__day + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.listing__country_latest + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( -- Join Standard Outputs SELECT - subq_17.country_latest AS listing__country_latest - , subq_14.metric_time__day AS metric_time__day - , subq_14.ds__day AS ds__day - , subq_14.ds__week AS ds__week - , subq_14.ds__month AS ds__month - , subq_14.ds__quarter AS ds__quarter - , subq_14.ds__year AS ds__year - , subq_14.ds__extract_year AS ds__extract_year - , subq_14.ds__extract_quarter AS ds__extract_quarter - , subq_14.ds__extract_month AS ds__extract_month - , subq_14.ds__extract_day AS ds__extract_day - , subq_14.ds__extract_dow AS ds__extract_dow - , subq_14.ds__extract_doy AS ds__extract_doy - , subq_14.ds_partitioned__day AS ds_partitioned__day - , subq_14.ds_partitioned__week AS ds_partitioned__week - , subq_14.ds_partitioned__month AS ds_partitioned__month - , subq_14.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_14.ds_partitioned__year AS ds_partitioned__year - , subq_14.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_14.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_14.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_14.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_14.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_14.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_14.paid_at__day AS paid_at__day - , subq_14.paid_at__week AS paid_at__week - , subq_14.paid_at__month AS paid_at__month - , subq_14.paid_at__quarter AS paid_at__quarter - , subq_14.paid_at__year AS paid_at__year - , subq_14.paid_at__extract_year AS paid_at__extract_year - , subq_14.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_14.paid_at__extract_month AS paid_at__extract_month - , subq_14.paid_at__extract_day AS paid_at__extract_day - , subq_14.paid_at__extract_dow AS paid_at__extract_dow - , subq_14.paid_at__extract_doy AS paid_at__extract_doy - , subq_14.booking__ds__day AS booking__ds__day - , subq_14.booking__ds__week AS booking__ds__week - , subq_14.booking__ds__month AS booking__ds__month - , subq_14.booking__ds__quarter AS booking__ds__quarter - , subq_14.booking__ds__year AS booking__ds__year - , subq_14.booking__ds__extract_year AS booking__ds__extract_year - , subq_14.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_14.booking__ds__extract_month AS booking__ds__extract_month - , subq_14.booking__ds__extract_day AS booking__ds__extract_day - , subq_14.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_14.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_14.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_14.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_14.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_14.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_14.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_14.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_14.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_14.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_14.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_14.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_14.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_14.booking__paid_at__day AS booking__paid_at__day - , subq_14.booking__paid_at__week AS booking__paid_at__week - , subq_14.booking__paid_at__month AS booking__paid_at__month - , subq_14.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_14.booking__paid_at__year AS booking__paid_at__year - , subq_14.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_14.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_14.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_14.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_14.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_14.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_14.metric_time__week AS metric_time__week - , subq_14.metric_time__month AS metric_time__month - , subq_14.metric_time__quarter AS metric_time__quarter - , subq_14.metric_time__year AS metric_time__year - , subq_14.metric_time__extract_year AS metric_time__extract_year - , subq_14.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_14.metric_time__extract_month AS metric_time__extract_month - , subq_14.metric_time__extract_day AS metric_time__extract_day - , subq_14.metric_time__extract_dow AS metric_time__extract_dow - , subq_14.metric_time__extract_doy AS metric_time__extract_doy - , subq_14.listing AS listing - , subq_14.guest AS guest - , subq_14.host AS host - , subq_14.booking__listing AS booking__listing - , subq_14.booking__guest AS booking__guest - , subq_14.booking__host AS booking__host - , subq_14.is_instant AS is_instant - , subq_14.booking__is_instant AS booking__is_instant - , subq_14.bookings AS bookings - , subq_14.instant_bookings AS instant_bookings - , subq_14.booking_value AS booking_value - , subq_14.max_booking_value AS max_booking_value - , subq_14.min_booking_value AS min_booking_value - , subq_14.bookers AS bookers - , subq_14.average_booking_value AS average_booking_value - , subq_14.referred_bookings AS referred_bookings - , subq_14.median_booking_value AS median_booking_value - , subq_14.booking_value_p99 AS booking_value_p99 - , subq_14.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_14.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_14.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_18.country_latest AS listing__country_latest + , subq_15.ds__day AS ds__day + , subq_15.ds__week AS ds__week + , subq_15.ds__month AS ds__month + , subq_15.ds__quarter AS ds__quarter + , subq_15.ds__year AS ds__year + , subq_15.ds__extract_year AS ds__extract_year + , subq_15.ds__extract_quarter AS ds__extract_quarter + , subq_15.ds__extract_month AS ds__extract_month + , subq_15.ds__extract_day AS ds__extract_day + , subq_15.ds__extract_dow AS ds__extract_dow + , subq_15.ds__extract_doy AS ds__extract_doy + , subq_15.ds_partitioned__day AS ds_partitioned__day + , subq_15.ds_partitioned__week AS ds_partitioned__week + , subq_15.ds_partitioned__month AS ds_partitioned__month + , subq_15.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_15.ds_partitioned__year AS ds_partitioned__year + , subq_15.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_15.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_15.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_15.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_15.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_15.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_15.paid_at__day AS paid_at__day + , subq_15.paid_at__week AS paid_at__week + , subq_15.paid_at__month AS paid_at__month + , subq_15.paid_at__quarter AS paid_at__quarter + , subq_15.paid_at__year AS paid_at__year + , subq_15.paid_at__extract_year AS paid_at__extract_year + , subq_15.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_15.paid_at__extract_month AS paid_at__extract_month + , subq_15.paid_at__extract_day AS paid_at__extract_day + , subq_15.paid_at__extract_dow AS paid_at__extract_dow + , subq_15.paid_at__extract_doy AS paid_at__extract_doy + , subq_15.booking__ds__day AS booking__ds__day + , subq_15.booking__ds__week AS booking__ds__week + , subq_15.booking__ds__month AS booking__ds__month + , subq_15.booking__ds__quarter AS booking__ds__quarter + , subq_15.booking__ds__year AS booking__ds__year + , subq_15.booking__ds__extract_year AS booking__ds__extract_year + , subq_15.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_15.booking__ds__extract_month AS booking__ds__extract_month + , subq_15.booking__ds__extract_day AS booking__ds__extract_day + , subq_15.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_15.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_15.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_15.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_15.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_15.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_15.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_15.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_15.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_15.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_15.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_15.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_15.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_15.booking__paid_at__day AS booking__paid_at__day + , subq_15.booking__paid_at__week AS booking__paid_at__week + , subq_15.booking__paid_at__month AS booking__paid_at__month + , subq_15.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_15.booking__paid_at__year AS booking__paid_at__year + , subq_15.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_15.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_15.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_15.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_15.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_15.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_15.metric_time__week AS metric_time__week + , subq_15.metric_time__month AS metric_time__month + , subq_15.metric_time__quarter AS metric_time__quarter + , subq_15.metric_time__year AS metric_time__year + , subq_15.metric_time__extract_year AS metric_time__extract_year + , subq_15.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_15.metric_time__extract_month AS metric_time__extract_month + , subq_15.metric_time__extract_day AS metric_time__extract_day + , subq_15.metric_time__extract_dow AS metric_time__extract_dow + , subq_15.metric_time__extract_doy AS metric_time__extract_doy + , subq_15.metric_time__day AS metric_time__day + , subq_15.listing AS listing + , subq_15.guest AS guest + , subq_15.host AS host + , subq_15.booking__listing AS booking__listing + , subq_15.booking__guest AS booking__guest + , subq_15.booking__host AS booking__host + , subq_15.is_instant AS is_instant + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings + , subq_15.instant_bookings AS instant_bookings + , subq_15.booking_value AS booking_value + , subq_15.max_booking_value AS max_booking_value + , subq_15.min_booking_value AS min_booking_value + , subq_15.bookers AS bookers + , subq_15.average_booking_value AS average_booking_value + , subq_15.referred_bookings AS referred_bookings + , subq_15.median_booking_value AS median_booking_value + , subq_15.booking_value_p99 AS booking_value_p99 + , subq_15.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_15.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_15.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -885,7 +885,7 @@ FROM ( , subq_11.metric_time__extract_day AS metric_time__extract_day , subq_11.metric_time__extract_dow AS metric_time__extract_dow , subq_11.metric_time__extract_doy AS metric_time__extract_doy - , subq_12.metric_time__day AS metric_time__day + , subq_14.metric_time__day AS metric_time__day , subq_11.listing AS listing , subq_11.guest AS guest , subq_11.host AS host @@ -908,11 +908,33 @@ FROM ( , subq_11.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_11.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_13.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 - ) subq_12 + subq_13.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_12.ds__day AS metric_time__day + , subq_12.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1131,83 @@ FROM ( ) subq_10 ) subq_11 ON - subq_12.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day - ) subq_14 + subq_14.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day + ) subq_15 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_16.listing - , subq_16.country_latest + subq_17.listing + , subq_17.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_16.ds__day + , subq_16.ds__week + , subq_16.ds__month + , subq_16.ds__quarter + , subq_16.ds__year + , subq_16.ds__extract_year + , subq_16.ds__extract_quarter + , subq_16.ds__extract_month + , subq_16.ds__extract_day + , subq_16.ds__extract_dow + , subq_16.ds__extract_doy + , subq_16.created_at__day + , subq_16.created_at__week + , subq_16.created_at__month + , subq_16.created_at__quarter + , subq_16.created_at__year + , subq_16.created_at__extract_year + , subq_16.created_at__extract_quarter + , subq_16.created_at__extract_month + , subq_16.created_at__extract_day + , subq_16.created_at__extract_dow + , subq_16.created_at__extract_doy + , subq_16.listing__ds__day + , subq_16.listing__ds__week + , subq_16.listing__ds__month + , subq_16.listing__ds__quarter + , subq_16.listing__ds__year + , subq_16.listing__ds__extract_year + , subq_16.listing__ds__extract_quarter + , subq_16.listing__ds__extract_month + , subq_16.listing__ds__extract_day + , subq_16.listing__ds__extract_dow + , subq_16.listing__ds__extract_doy + , subq_16.listing__created_at__day + , subq_16.listing__created_at__week + , subq_16.listing__created_at__month + , subq_16.listing__created_at__quarter + , subq_16.listing__created_at__year + , subq_16.listing__created_at__extract_year + , subq_16.listing__created_at__extract_quarter + , subq_16.listing__created_at__extract_month + , subq_16.listing__created_at__extract_day + , subq_16.listing__created_at__extract_dow + , subq_16.listing__created_at__extract_doy + , subq_16.ds__day AS metric_time__day + , subq_16.ds__week AS metric_time__week + , subq_16.ds__month AS metric_time__month + , subq_16.ds__quarter AS metric_time__quarter + , subq_16.ds__year AS metric_time__year + , subq_16.ds__extract_year AS metric_time__extract_year + , subq_16.ds__extract_quarter AS metric_time__extract_quarter + , subq_16.ds__extract_month AS metric_time__extract_month + , subq_16.ds__extract_day AS metric_time__extract_day + , subq_16.ds__extract_dow AS metric_time__extract_dow + , subq_16.ds__extract_doy AS metric_time__extract_doy + , subq_16.listing + , subq_16.user + , subq_16.listing__user + , subq_16.country_latest + , subq_16.is_lux_latest + , subq_16.capacity_latest + , subq_16.listing__country_latest + , subq_16.listing__is_lux_latest + , subq_16.listing__capacity_latest + , subq_16.listings + , subq_16.largest_listing + , subq_16.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1246,27 +1268,27 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_16 + ) subq_17 + ) subq_18 ON - subq_14.listing = subq_17.listing - ) subq_18 + subq_15.listing = subq_18.listing + ) subq_19 WHERE booking__is_instant - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 GROUP BY - subq_20.metric_time__day - , subq_20.listing__country_latest - ) subq_21 - ) subq_22 + subq_21.metric_time__day + , subq_21.listing__country_latest + ) subq_22 + ) subq_23 ON ( - subq_9.listing__country_latest = subq_22.listing__country_latest + subq_9.listing__country_latest = subq_23.listing__country_latest ) AND ( - subq_9.metric_time__day = subq_22.metric_time__day + subq_9.metric_time__day = subq_23.metric_time__day ) GROUP BY - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) -) subq_23 + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) +) subq_24 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 e8368747af..8a9e6654d7 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 @@ -14,10 +14,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_46.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_48.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_48.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_48.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -31,9 +31,9 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_25.metric_time__day AS metric_time__day - , subq_25.booking__is_instant AS booking__is_instant - , subq_25.bookings AS bookings + , subq_26.metric_time__day AS metric_time__day + , subq_26.booking__is_instant AS booking__is_instant + , subq_26.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,17 +43,17 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_25 + ) subq_26 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_25.listing = listings_latest_src_28000.listing_id - ) subq_29 + subq_26.listing = listings_latest_src_28000.listing_id + ) subq_30 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_33 + ) subq_34 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -67,17 +67,17 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_38.metric_time__day AS metric_time__day - , subq_38.booking__is_instant AS booking__is_instant - , subq_38.bookings AS bookings + , subq_40.metric_time__day AS metric_time__day + , subq_40.booking__is_instant AS booking__is_instant + , subq_40.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_37.ds AS metric_time__day - , subq_35.listing AS listing - , subq_35.booking__is_instant AS booking__is_instant - , subq_35.bookings AS bookings - FROM ***************************.mf_time_spine subq_37 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_36.listing AS listing + , subq_36.booking__is_instant AS booking__is_instant + , subq_36.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -87,27 +87,27 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_35 + ) subq_36 ON - subq_37.ds - INTERVAL 14 day = subq_35.metric_time__day - ) subq_38 + DATE_TRUNC('day', time_spine_src_28006.ds) - INTERVAL 14 day = subq_36.metric_time__day + ) subq_40 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_38.listing = listings_latest_src_28000.listing_id - ) subq_42 + subq_40.listing = listings_latest_src_28000.listing_id + ) subq_44 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_46 + ) subq_48 ON ( - subq_33.listing__country_latest = subq_46.listing__country_latest + subq_34.listing__country_latest = subq_48.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_46.metric_time__day + subq_34.metric_time__day = subq_48.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_46.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_46.listing__country_latest) -) subq_47 + COALESCE(subq_34.metric_time__day, subq_48.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_48.listing__country_latest) +) subq_49 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 6a063e32fc..5cd3e39bcd 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 @@ -8,27 +8,49 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS bookings_join_to_time_spine + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS bookings_join_to_time_spine FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +367,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 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 c5ff38a66d..7bb3a620b2 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 @@ -15,10 +15,10 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -35,13 +35,13 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day -) subq_16 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 82c85e9bd4..072ba84ad2 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS instant_bookings_with_measure_filter + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS instant_bookings_with_measure_filter FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE metric_time__day > '2020-01-01' ) subq_7 - WHERE metric_time__day > '2020-01-01' - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,5 +368,5 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 12b8e97468..00a4cfcafc 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS instant_bookings_with_measure_filter + subq_18.metric_time__day AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS instant_bookings_with_measure_filter FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT - ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 WHERE metric_time__day > '2020-01-01' -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -41,11 +43,11 @@ LEFT OUTER JOIN ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((booking__is_instant) AND (listing IS NOT NULL)) AND (metric_time__day > '2020-01-01') GROUP BY metric_time__day , booking__is_instant -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day 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 2ce1521c99..1bfb02b137 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 @@ -6,25 +6,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.bookings + subq_9.metric_time__day + , subq_9.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - 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' - ) subq_5 + subq_7.metric_time__day + FROM ( + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + SELECT + subq_6.ds__day + , subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_7 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -338,7 +366,7 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day + ) subq_9 + WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_10 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 6e1385158a..2566be75ad 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 @@ -12,15 +12,18 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings + subq_19.metric_time__day AS metric_time__day + , subq_15.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT - ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 - WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + DATE_TRUNC('day', ds) AS metric_time__day + FROM ***************************.mf_time_spine time_spine_src_28006 + WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,11 +39,11 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_12 + ) subq_14 GROUP BY metric_time__day - ) subq_13 + ) subq_15 ON - subq_14.metric_time__day = subq_13.metric_time__day - WHERE subq_14.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_17 + subq_19.metric_time__day = subq_15.metric_time__day + WHERE subq_19.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_21 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 a916df15a5..11d9d5030b 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 @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_join_to_time_spine + subq_7.metric_time__day + , subq_7.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +249,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 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 c8ecb775a6..ea92d9c51b 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 @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings_join_to_time_spine -FROM ***************************.mf_time_spine subq_12 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_11.bookings AS bookings_join_to_time_spine +FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day -) subq_10 +) subq_11 ON - subq_12.ds = subq_10.metric_time__day + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.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 67dfb9f894..94b6ac4cf0 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 @@ -6,19 +6,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 + subq_8.metric_time__day + , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +354,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day +) subq_8 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 8a474a7060..1437800759 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 @@ -11,9 +11,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_14.ds AS metric_time__day - , subq_12.bookings AS bookings - FROM ***************************.mf_time_spine subq_14 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_13.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -29,11 +29,11 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_12 + ) subq_13 ON - subq_14.ds = subq_12.metric_time__day -) subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_13.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 37c2eb64f5..0b115cedfc 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 @@ -6,27 +6,49 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_9.metric_time__day + , subq_9.booking__is_instant + , COALESCE(subq_9.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +365,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 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 6a3d97a372..8615fe56a8 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 @@ -18,10 +18,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -38,14 +38,14 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19