From bcd959cf70342778d50d5e30e8f43aa5028ed155 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 24 Oct 2024 17:20:31 -0700 Subject: [PATCH 1/8] Support both MetricTimeDimensionTransformNodes and ReadSqlSourceNodes for time spines The metric time nodes are used for resolving metric_time without metrics. The read SQL nodes will be used for time spine joins. --- .../dataflow/builder/dataflow_plan_builder.py | 20 ++++++++++--- metricflow/dataflow/builder/node_evaluator.py | 6 ++-- metricflow/dataflow/builder/source_node.py | 28 ++++++++++++------- metricflow/plan_conversion/node_processor.py | 4 +-- .../dataflow/builder/test_node_evaluator.py | 8 +++--- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index bc7fbd8dad..896dad428e 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -87,8 +87,10 @@ 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.where_filter import WhereConstraintNode from metricflow.dataflow.nodes.window_reaggregation_node import WindowReaggregationNode @@ -1037,8 +1039,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_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 @@ -1077,7 +1078,7 @@ def _find_source_node_recipe_non_cached( desired_linkable_specs=linkable_specs_to_satisfy_tuple, nodes=candidate_nodes_for_right_side_of_join, metric_time_dimension_reference=self._metric_time_dimension_reference, - time_spine_nodes=self._source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=self._source_node_set.time_spine_metric_time_nodes_tuple, ) logger.debug( LazyFormat( @@ -1124,7 +1125,7 @@ def _find_source_node_recipe_non_cached( semantic_model_lookup=self._semantic_model_lookup, nodes_available_for_joins=self._sort_by_suitability(candidate_nodes_for_right_side_of_join), node_data_set_resolver=self._node_data_set_resolver, - time_spine_nodes=self._source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=self._source_node_set.time_spine_metric_time_nodes_tuple, ) # Dict from the node that contains the source node to the evaluation results. @@ -1812,3 +1813,14 @@ 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] diff --git a/metricflow/dataflow/builder/node_evaluator.py b/metricflow/dataflow/builder/node_evaluator.py index fbc11da094..fb62adc915 100644 --- a/metricflow/dataflow/builder/node_evaluator.py +++ b/metricflow/dataflow/builder/node_evaluator.py @@ -169,7 +169,7 @@ def __init__( semantic_model_lookup: SemanticModelLookup, nodes_available_for_joins: Sequence[DataflowPlanNode], node_data_set_resolver: DataflowPlanNodeOutputDataSetResolver, - time_spine_nodes: Sequence[MetricTimeDimensionTransformNode], + time_spine_metric_time_nodes: Sequence[MetricTimeDimensionTransformNode], ) -> None: """Initializer. @@ -186,7 +186,7 @@ def __init__( self._node_data_set_resolver = node_data_set_resolver self._partition_resolver = PartitionJoinResolver(self._semantic_model_lookup) self._join_evaluator = SemanticModelJoinEvaluator(self._semantic_model_lookup) - self._time_spine_nodes = time_spine_nodes + self._time_spine_metric_time_nodes = time_spine_metric_time_nodes def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs( self, @@ -205,7 +205,7 @@ def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs( linkable_specs_in_right_node = data_set_in_right_node.instance_set.spec_set.linkable_specs # If right node is time spine source node, use cross join. - if right_node in self._time_spine_nodes: + if right_node in self._time_spine_metric_time_nodes: satisfiable_metric_time_specs = [ spec for spec in linkable_specs_in_right_node if spec in needed_linkable_specs ] diff --git a/metricflow/dataflow/builder/source_node.py b/metricflow/dataflow/builder/source_node.py index 575668eabb..1e84980179 100644 --- a/metricflow/dataflow/builder/source_node.py +++ b/metricflow/dataflow/builder/source_node.py @@ -36,20 +36,23 @@ class SourceNodeSet: # Semantic models are 1:1 mapped to a ReadSqlSourceNode. source_nodes_for_group_by_item_queries: Tuple[DataflowPlanNode, ...] - # Provides the time spines. - time_spine_nodes: Mapping[TimeGranularity, MetricTimeDimensionTransformNode] + # Provides time spines that can be used to satisfy time spine joins. + time_spine_read_nodes: Mapping[TimeGranularity, ReadSqlSourceNode] + + # Provides time spines that can be used to satisfy metric_time without metrics. + time_spine_metric_time_nodes: Mapping[TimeGranularity, MetricTimeDimensionTransformNode] @property def all_nodes(self) -> Sequence[DataflowPlanNode]: # noqa: D102 return ( self.source_nodes_for_metric_queries + self.source_nodes_for_group_by_item_queries - + self.time_spine_nodes_tuple + + self.time_spine_metric_time_nodes_tuple ) @property - def time_spine_nodes_tuple(self) -> Tuple[MetricTimeDimensionTransformNode, ...]: # noqa: D102 - return tuple(self.time_spine_nodes.values()) + def time_spine_metric_time_nodes_tuple(self) -> Tuple[MetricTimeDimensionTransformNode, ...]: # noqa: D102 + return tuple(self.time_spine_metric_time_nodes.values()) class SourceNodeBuilder: @@ -65,11 +68,15 @@ def __init__( # noqa: D107 self.time_spine_sources = TimeSpineSource.build_standard_time_spine_sources( semantic_manifest_lookup.semantic_manifest ) - self._time_spine_source_nodes = {} - for granularity, time_spine_source in self.time_spine_sources.items(): + + self._time_spine_read_nodes = {} + self._time_spine_metric_time_nodes = {} + for base_granularity, time_spine_source in self.time_spine_sources.items(): data_set = data_set_converter.build_time_spine_source_data_set(time_spine_source) - self._time_spine_source_nodes[granularity] = MetricTimeDimensionTransformNode.create( - parent_node=ReadSqlSourceNode.create(data_set), + read_node = ReadSqlSourceNode.create(data_set) + self._time_spine_read_nodes[base_granularity] = read_node + self._time_spine_metric_time_nodes[base_granularity] = MetricTimeDimensionTransformNode.create( + parent_node=read_node, aggregation_time_dimension_reference=TimeDimensionReference(time_spine_source.base_column), ) @@ -103,7 +110,8 @@ def create_from_data_sets(self, data_sets: Sequence[SemanticModelDataSet]) -> So source_nodes_for_metric_queries.append(metric_time_transform_node) return SourceNodeSet( - time_spine_nodes=self._time_spine_source_nodes, + time_spine_metric_time_nodes=self._time_spine_metric_time_nodes, + time_spine_read_nodes=self._time_spine_read_nodes, source_nodes_for_group_by_item_queries=tuple(group_by_item_source_nodes), source_nodes_for_metric_queries=tuple(source_nodes_for_metric_queries), ) diff --git a/metricflow/plan_conversion/node_processor.py b/metricflow/plan_conversion/node_processor.py index 19ce50acfe..bbeca250c0 100644 --- a/metricflow/plan_conversion/node_processor.py +++ b/metricflow/plan_conversion/node_processor.py @@ -622,7 +622,7 @@ def remove_unnecessary_nodes( desired_linkable_specs: Sequence[LinkableInstanceSpec], nodes: Sequence[DataflowPlanNode], metric_time_dimension_reference: TimeDimensionReference, - time_spine_nodes: Sequence[MetricTimeDimensionTransformNode], + time_spine_metric_time_nodes: Sequence[MetricTimeDimensionTransformNode], ) -> List[DataflowPlanNode]: """Filters out many of the nodes that can't possibly be useful for joins to obtain the desired linkable specs. @@ -668,7 +668,7 @@ def remove_unnecessary_nodes( continue # Used for group-by-item-values queries. - if node in time_spine_nodes: + if node in time_spine_metric_time_nodes: logger.debug(LazyFormat(lambda: f"Including {node} since it matches `time_spine_node`")) relevant_nodes.append(node) continue diff --git a/tests_metricflow/dataflow/builder/test_node_evaluator.py b/tests_metricflow/dataflow/builder/test_node_evaluator.py index 20d932421d..f4785806e4 100644 --- a/tests_metricflow/dataflow/builder/test_node_evaluator.py +++ b/tests_metricflow/dataflow/builder/test_node_evaluator.py @@ -49,7 +49,7 @@ def node_evaluator( ].semantic_manifest_lookup.semantic_model_lookup, nodes_available_for_joins=tuple(mf_engine_fixture.read_node_mapping.values()), node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=mf_engine_fixture.source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=mf_engine_fixture.source_node_set.time_spine_metric_time_nodes_tuple, ) @@ -73,7 +73,7 @@ def make_multihop_node_evaluator( desired_linkable_specs=desired_linkable_specs, nodes=source_node_set.source_nodes_for_metric_queries, metric_time_dimension_reference=DataSet.metric_time_dimension_reference(), - time_spine_nodes=source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=source_node_set.time_spine_metric_time_nodes_tuple, ) nodes_available_for_joins = list( @@ -88,7 +88,7 @@ def make_multihop_node_evaluator( semantic_model_lookup=semantic_manifest_lookup_with_multihop_links.semantic_model_lookup, nodes_available_for_joins=nodes_available_for_joins, node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=source_node_set.time_spine_metric_time_nodes_tuple, ) @@ -521,7 +521,7 @@ def test_node_evaluator_with_scd_target( # Use all nodes in the simple model as candidates for joins. nodes_available_for_joins=tuple(mf_engine_fixture.read_node_mapping.values()), node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=mf_engine_fixture.source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=mf_engine_fixture.source_node_set.time_spine_metric_time_nodes_tuple, ) evaluation = node_evaluator.evaluate_node( From f6f44f0cdb6dbc71c2acd1bd606aaaa6a1e4baf5 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 08:26:37 -0800 Subject: [PATCH 2/8] Add TransformTimeDimensionsNode --- metricflow/dataflow/dataflow_plan_visitor.py | 11 ++- .../nodes/transform_time_dimensions.py | 74 +++++++++++++++++++ .../optimizer/predicate_pushdown_optimizer.py | 6 ++ .../source_scan/cm_branch_combiner.py | 7 ++ .../source_scan/source_scan_optimizer.py | 7 ++ metricflow/dataset/sql_dataset.py | 16 ++++ metricflow/execution/dataflow_to_execution.py | 5 ++ metricflow/plan_conversion/dataflow_to_sql.py | 57 ++++++++++++++ .../source_scan/test_source_scan_optimizer.py | 4 + 9 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 metricflow/dataflow/nodes/transform_time_dimensions.py diff --git a/metricflow/dataflow/dataflow_plan_visitor.py b/metricflow/dataflow/dataflow_plan_visitor.py index 4c6ad85620..06d88c21df 100644 --- a/metricflow/dataflow/dataflow_plan_visitor.py +++ b/metricflow/dataflow/dataflow_plan_visitor.py @@ -25,6 +25,7 @@ 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 @@ -121,6 +122,10 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> V def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> VisitorOutputT: # noqa: D102 raise NotImplementedError + @abstractmethod + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> VisitorOutputT: # noqa: D102 + raise NotImplementedError + class DataflowPlanNodeVisitorWithDefaultHandler(DataflowPlanNodeVisitor[VisitorOutputT], Generic[VisitorOutputT]): """Similar to `DataflowPlanNodeVisitor`, but with an abstract default handler that gets called for each node. @@ -191,7 +196,7 @@ def visit_semi_additive_join_node(self, node: SemiAdditiveJoinNode) -> VisitorOu @override def visit_metric_time_dimension_transform_node( # noqa: D102 self, node: MetricTimeDimensionTransformNode - ) -> VisitorOutputT: # noqa: D102 + ) -> VisitorOutputT: return self._default_handler(node) @override @@ -213,3 +218,7 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> V @override def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> VisitorOutputT: # noqa: D102 return self._default_handler(node) + + @override + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> VisitorOutputT: # noqa: D102 + return self._default_handler(node) diff --git a/metricflow/dataflow/nodes/transform_time_dimensions.py b/metricflow/dataflow/nodes/transform_time_dimensions.py new file mode 100644 index 0000000000..b0dc876509 --- /dev/null +++ b/metricflow/dataflow/nodes/transform_time_dimensions.py @@ -0,0 +1,74 @@ +from __future__ import annotations + +from abc import ABC +from dataclasses import dataclass +from typing import Sequence + +from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix +from metricflow_semantics.dag.mf_dag import DisplayedProperty +from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec +from metricflow_semantics.visitor import VisitorOutputT + +from metricflow.dataflow.dataflow_plan import DataflowPlanNode +from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor + + +@dataclass(frozen=True, eq=False) +class TransformTimeDimensionsNode(DataflowPlanNode, ABC): + """Change the columns in the parent node to match the requested time dimension specs. + + Args: + requested_time_dimension_specs: The time dimension specs to match in the parent node and transform. + """ + + requested_time_dimension_specs: Sequence[TimeDimensionSpec] + + def __post_init__(self) -> None: # noqa: D105 + super().__post_init__() + assert ( + len(self.requested_time_dimension_specs) > 0 + ), "Must have at least one value in requested_time_dimension_specs for TransformTimeDimensionsNode." + + @staticmethod + def create( # noqa: D102 + parent_node: DataflowPlanNode, requested_time_dimension_specs: Sequence[TimeDimensionSpec] + ) -> TransformTimeDimensionsNode: + return TransformTimeDimensionsNode( + parent_nodes=(parent_node,), requested_time_dimension_specs=requested_time_dimension_specs + ) + + @classmethod + def id_prefix(cls) -> IdPrefix: # noqa: D102 + return StaticIdPrefix.DATAFLOW_NODE_JOIN_TO_CUSTOM_GRANULARITY_ID_PREFIX + + def accept(self, visitor: DataflowPlanNodeVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 + return visitor.visit_transform_time_dimensions_node(self) + + @property + def description(self) -> str: # noqa: D102 + return """Transform Time Dimension Columns""" + + @property + def displayed_properties(self) -> Sequence[DisplayedProperty]: # noqa: D102 + return tuple(super().displayed_properties) + ( + DisplayedProperty("requested_time_dimension_specs", self.requested_time_dimension_specs), + ) + + @property + def parent_node(self) -> DataflowPlanNode: # noqa: D102 + return self.parent_nodes[0] + + def functionally_identical(self, other_node: DataflowPlanNode) -> bool: # noqa: D102 + return ( + isinstance(other_node, self.__class__) + and other_node.requested_time_dimension_specs == self.requested_time_dimension_specs + ) + + def with_new_parents( # noqa: D102 + self, new_parent_nodes: Sequence[DataflowPlanNode] + ) -> TransformTimeDimensionsNode: + assert len(new_parent_nodes) == 1, "TransformTimeDimensionsNode accepts exactly one parent node." + return TransformTimeDimensionsNode.create( + parent_node=new_parent_nodes[0], + requested_time_dimension_specs=self.requested_time_dimension_specs, + ) diff --git a/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py b/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py index ba9e6d7661..b008c6d2a2 100644 --- a/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py +++ b/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py @@ -33,6 +33,7 @@ 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 @@ -468,6 +469,11 @@ def visit_join_to_custom_granularity_node( # noqa: D102 ) -> OptimizeBranchResult: raise NotImplementedError + def visit_transform_time_dimensions_node( # noqa: D102 + self, node: TransformTimeDimensionsNode + ) -> OptimizeBranchResult: + raise NotImplementedError + def visit_join_on_entities_node(self, node: JoinOnEntitiesNode) -> OptimizeBranchResult: """Handles pushdown state propagation for the standard join node type. diff --git a/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py b/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py index e873873855..6b384f72f8 100644 --- a/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py +++ b/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py @@ -27,6 +27,7 @@ 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 @@ -460,3 +461,9 @@ def visit_join_to_custom_granularity_node( # noqa: D102 def visit_min_max_node(self, node: MinMaxNode) -> ComputeMetricsBranchCombinerResult: # noqa: D102 self._log_visit_node_type(node) return self._default_handler(node) + + def visit_transform_time_dimensions_node( # noqa: D102 + self, node: TransformTimeDimensionsNode + ) -> ComputeMetricsBranchCombinerResult: + self._log_visit_node_type(node) + return self._default_handler(node) diff --git a/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py b/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py index dd1fe04464..baa946d8b1 100644 --- a/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py +++ b/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py @@ -29,6 +29,7 @@ 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 @@ -324,3 +325,9 @@ def visit_join_to_custom_granularity_node( # noqa: D102 def visit_min_max_node(self, node: MinMaxNode) -> OptimizeBranchResult: # noqa: D102 self._log_visit_node_type(node) return self._default_base_output_handler(node) + + def visit_transform_time_dimensions_node( # noqa: D102 + self, node: TransformTimeDimensionsNode + ) -> OptimizeBranchResult: + self._log_visit_node_type(node) + return self._default_base_output_handler(node) 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/execution/dataflow_to_execution.py b/metricflow/execution/dataflow_to_execution.py index fa0518e847..bdefd24134 100644 --- a/metricflow/execution/dataflow_to_execution.py +++ b/metricflow/execution/dataflow_to_execution.py @@ -26,6 +26,7 @@ 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 @@ -200,3 +201,7 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> C @override def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> ConvertToExecutionPlanResult: raise NotImplementedError + + @override + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> ConvertToExecutionPlanResult: + raise NotImplementedError diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 0b4badcdd6..a4d01496bb 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 @@ -65,6 +66,7 @@ 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 @@ -1485,6 +1487,55 @@ def _get_custom_granularity_column_name(self, custom_granularity_name: str) -> s f"Custom granularity {custom_granularity} not found. This indicates internal misconfiguration." ) + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> SqlDataSet: # noqa: D102 + 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) @@ -2112,5 +2163,11 @@ def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNod node=node, node_to_select_subquery_function=super().visit_join_to_custom_granularity_node ) + @override + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> SqlDataSet: # noqa: D102 + return self._default_handler( + node=node, node_to_select_subquery_function=super().visit_transform_time_dimensions_node + ) + DataflowNodeT = TypeVar("DataflowNodeT", bound=DataflowPlanNode) diff --git a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py index 01143c4c18..0bf63ac3a5 100644 --- a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py +++ b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py @@ -34,6 +34,7 @@ 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 @@ -110,6 +111,9 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> i def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> int: # noqa: D102 return self._sum_parents(node) + def visit_transform_time_dimensions_node(self, node: TransformTimeDimensionsNode) -> int: # noqa: D102 + return self._sum_parents(node) + def count_source_nodes(self, dataflow_plan: DataflowPlan) -> int: # noqa: D102 return dataflow_plan.sink_node.accept(self) From 1ec4c63175babdd9b0e7300b8c703e1eb416435b Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 22:07:55 -0800 Subject: [PATCH 3/8] Add logic to build time spine nodes in the dataflow plan This will allow us to stop building time spine nodes on the fly in the dataflow to SQL logic. --- .../dataflow/builder/dataflow_plan_builder.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 896dad428e..9efa9b7bad 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -92,6 +92,7 @@ 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 @@ -1824,3 +1825,37 @@ def _choose_time_spine_metric_time_node( 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] + + 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 + + # TODO: support multiple time spines here. Build node on the one with the smallest base grain. + # Then, pass custom_granularity_specs into _build_pre_aggregation_plan if they aren't satisfied by smallest time spine. + 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)), + time_range_constraint=time_range_constraint, + where_filter_specs=where_filter_specs, + distinct=should_dedupe, + ) From 2808b0b11f225eb784dd958a86dcbf3e68d481d4 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 22:10:18 -0800 Subject: [PATCH 4/8] Integrate new time spine nodes into JoinToTimeSpineNodes --- .../dataflow/builder/dataflow_plan_builder.py | 72 ++++++++++--- .../dataflow/nodes/join_to_time_spine.py | 32 ++---- metricflow/plan_conversion/dataflow_to_sql.py | 102 +++++++----------- 3 files changed, 109 insertions(+), 97 deletions(-) diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 9efa9b7bad..87d6490bbe 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 @@ -649,14 +650,19 @@ def _build_derived_metric_output_node( metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup ) if metric_spec.has_time_offset and queried_agg_time_dimension_specs: + # TODO: move this to a helper method + 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, ) + # TODO: fix bug here where filter specs are being included in when aggregating. if len(metric_spec.filter_spec_set.all_filter_specs) > 0 or predicate_pushdown_state.time_range_constraint: # FilterElementsNode will only be needed if there are where filter specs that were selected in the group by. specs_in_filters = set( @@ -1617,15 +1623,22 @@ 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 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 + + join_on_time_dimension_spec = self._determine_time_spine_join_spec( + measure_properties=measure_properties, required_time_spine_specs=base_queried_agg_time_dimension_specs + ) + required_time_spine_specs = (join_on_time_dimension_spec,) + base_queried_agg_time_dimension_specs + time_spine_node = self._build_time_spine_node(required_time_spine_specs) unaggregated_measure_node = JoinToTimeSpineNode.create( parent_node=unaggregated_measure_node, + 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, @@ -1668,10 +1681,13 @@ def _build_aggregated_measure_from_measure_source_node( 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] = [] @@ -1681,24 +1697,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. + 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 @@ -1859,3 +1874,34 @@ def _build_time_spine_node( 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(), + ), + ) + + def _determine_time_spine_join_spec( + self, measure_properties: MeasureSpecProperties, required_time_spine_specs: Tuple[TimeDimensionSpec, ...] + ) -> TimeDimensionSpec: + """Determine the spec to join on for a time spine join. + + Defaults to metric_time if it is included in the request, else the agg_time_dimension. + Will use the smallest available grain for the meeasure. + """ + 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 + ) + return join_on_time_dimension_spec 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/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index a4d01496bb..c00fed85f2 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -313,6 +313,7 @@ def _next_unique_table_alias(self) -> str: """Return the next unique table alias to use in generating queries.""" return SequentialIdGenerator.create_next_id(StaticIdPrefix.SUB_QUERY).str_value + # TODO: replace this with a dataflow plan node for cumulative metrics def _make_time_spine_data_set( self, agg_time_dimension_instances: Tuple[TimeDimensionInstance, ...], @@ -1372,97 +1373,72 @@ 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. 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, From 027a5bbe4fd7e08a0bc4a37707d4f5b0d6470e5b Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 17:00:49 -0800 Subject: [PATCH 5/8] Update DuckDB snapshots --- ...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 | 588 +++++---- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 | 19 +- ...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 | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- 121 files changed, 6495 insertions(+), 4768 deletions(-) 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..2c374bed8d 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 + 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 + 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..1bab2d34dc 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 + 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 + 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 + 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 + 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..fa3418d78d 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,96 @@ docstring: - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -489,43 +564,118 @@ docstring: - + - - - + + + - - + + - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -533,50 +683,50 @@ docstring: - + - + - + - + - - + + - + - + - + - + - + - + - + @@ -594,19 +744,19 @@ docstring: - + - + - + - - + + @@ -614,239 +764,239 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1010,260 +1160,260 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1271,273 +1421,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..8ee78b0844 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 + 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..e22a6a6837 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 + , 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 + 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..7d2f0270f6 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,45 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 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..efe04ccdcb 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,39 @@ 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.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..3f621b90ec 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 + 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..7de34b0ee2 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 + 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 + 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..0868ab6528 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 + 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..139cbfa160 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 + 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 + 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 + 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..b1a5dc4229 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 + 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..90bd2622f7 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 + 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' + time_spine_src_28006.ds - INTERVAL 2 day = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + 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..ba396053f8 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 + 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..6c821139f5 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 + 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..e72d76df27 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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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..6ed57c892f 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..d26cf723d2 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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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..6845f9bc09 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 + 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..705f82e6b1 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 + 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 + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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..d249202bf2 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..29d1a6106a 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 + 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..04acc1d8fa 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 + 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 + 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..3be3f783eb 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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 + time_spine_src_28006.ds - INTERVAL 1 month = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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..91c98ad536 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..d46a8c2a70 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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 + 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..f5b3979e4e 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 + 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..f32446618c 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 + 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 + 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..d7fe869604 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 + 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..adf2d6a797 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 + 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 + time_spine_src_28006.ds - INTERVAL 2 day = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + 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..579e062b67 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 + 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..8a8f9c46d1 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 + 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) + time_spine_src_28006.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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..bcca782caa 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 + 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..9de842c717 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 + 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 + time_spine_src_28006.ds - INTERVAL 5 day = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + 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..2dc8c37447 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 + 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 + 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..42b7243264 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 + 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 + 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 + 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 + 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 + 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..6574468fc3 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 + 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..37b1d7d77c 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 + 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', 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..9d009a63eb 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 + 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 + 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..fe15c86bd4 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 + 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 + 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 + time_spine_src_28006.ds - INTERVAL 5 day = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + 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..bdad0167e7 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 + 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 + 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..6a16e0902d 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 + 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 + 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 + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + 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 + time_spine_src_28006.ds - INTERVAL 2 day = subq_24.metric_time__day + WHERE 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..dce7677f8c 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 + 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 + 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..c25d4f0b95 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 + 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 + 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 + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - ) subq_24 + 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..438068b201 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..bf2aed0b01 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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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..a9c44081f1 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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..95d682c27d 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 + 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', 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 + 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..7390bca8b2 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 + 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..c9d0b3138b 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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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..a456e1772f 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..408e5a6216 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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 + 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..1d63126549 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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..917fe0c41d 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 + 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) + 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 + 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..8b6e243b55 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 + 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..cc540d2ea3 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 + 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 + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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..ffc964561e 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 + 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..749d48dc37 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 + 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' + time_spine_src_28006.ds - INTERVAL 5 day = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + 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..0404b12194 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 + 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..15065b1c75 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 + 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 + 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..9c6d01cbf9 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 + 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 + 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..cdf3094953 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 + 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 + 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 + 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 + time_spine_src_28006.ds - INTERVAL 14 day = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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..e61c6560d5 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 + 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..22b4d8635d 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('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..32956d46d5 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 + 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..4925b24181 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('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..f0f1df7cb2 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 + 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..c55dfdb349 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('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..7490846fbf 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 + 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..da330d7b46 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 + 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..d7b9ba7468 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 + 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..b486d4a122 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('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..05cf9d9e9d 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 + 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..2f994958df 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 + 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 + 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..bc2012ed56 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 + 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..26c3dd77d5 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] 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__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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..79f6aef9ba 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 + 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..97979a296a 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 + 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..ea9ced6c5e 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 + 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 + 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..6bfb266bde 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 + 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..e30c1c2353 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 + 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 + 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..46c51280ec 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 + 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..d1809f3035 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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + 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..6dfe1257a1 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 + 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..7d57881f43 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 + 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 + time_spine_src_28005.ts - INTERVAL 1 hour = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + 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..f7089fb16e 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 + 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..88b1899430 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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..ef528b6b81 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 + 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 + 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 + 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..e7595b9869 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 + 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 + 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 + 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 + 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 + 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 + 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..b6444d8888 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 + 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..f9105f81a2 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 + 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 + 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..7d639689d3 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 + 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..8ca9901dab 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 + 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 + 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..de9b4ae678 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 + 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..ad75aec551 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 + 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..23f94edf64 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 + 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..70c711ace8 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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) 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..8a3e5a8345 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 + 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..7be71a09b5 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 + 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 + 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..418ae5b38e 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 + 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..58b71e0dc5 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 + 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 + 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..3b4a444077 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 + 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..473dd7f259 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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 From 585b6987572c13f1b1e07fa11ebf507756a08724 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 17:03:10 -0800 Subject: [PATCH 6/8] Add tests for join to time spine metrics with custom grain filters --- .../test_custom_granularity.py | 54 +++ ..._with_custom_granularity_filter__plan0.sql | 376 ++++++++++++++++++ ...om_granularity_filter__plan0_optimized.sql | 56 +++ ...nularity_filter_not_in_group_by__plan0.sql | 374 +++++++++++++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 +++ 5 files changed, 916 insertions(+) create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql diff --git a/tests_metricflow/query_rendering/test_custom_granularity.py b/tests_metricflow/query_rendering/test_custom_granularity.py index 07823f07b1..4043c7b97d 100644 --- a/tests_metricflow/query_rendering/test_custom_granularity.py +++ b/tests_metricflow/query_rendering/test_custom_granularity.py @@ -556,3 +556,57 @@ def test_join_to_time_spine_metric_grouped_by_custom_grain( # noqa: D103 dataflow_plan_builder=dataflow_plan_builder, query_spec=query_spec, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, +) -> None: + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__martian_day",), + where_constraints=[ + PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-01'")) + ], + ).query_spec + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, +) -> None: + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__day",), + where_constraints=[ + PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-01'")) + ], + ).query_spec + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + ) diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..22ce29543e --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..e3c6553198 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..c5e3f7c58f --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..b88e399328 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day From 492043e4ad23587f3a4712e579f73d6cec332c31 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 22:45:44 -0800 Subject: [PATCH 7/8] Update SQL engine snapshots --- ...timespine_and_fill_nulls_with_0__plan0.sql | 456 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 66 +- ...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.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...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.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ..._metric_with_non_default_grains__plan0.sql | 78 +- ...th_non_default_grains__plan0_optimized.sql | 30 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 42 +- ...ouped_by_custom_grain__plan0_optimized.sql | 24 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 4 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._metric_with_custom_granularity__plan0.sql | 62 +- ...th_custom_granularity__plan0_optimized.sql | 16 +- ...nularity_filter_not_in_group_by__plan0.sql | 262 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ...set_metric_with_time_constraint__plan0.sql | 256 ++-- ..._with_time_constraint__plan0_optimized.sql | 22 +- ...nth_dimension_and_offset_window__plan0.sql | 56 +- ...ion_and_offset_window__plan0_optimized.sql | 12 +- ...ved_metric_with_offset_to_grain__plan0.sql | 64 +- ..._with_offset_to_grain__plan0_optimized.sql | 26 +- ...offset_to_grain_and_granularity__plan0.sql | 72 +- ...grain_and_granularity__plan0_optimized.sql | 28 +- ...rived_metric_with_offset_window__plan0.sql | 64 +- ...ic_with_offset_window__plan0_optimized.sql | 26 +- ...h_offset_window_and_granularity__plan0.sql | 70 +- ...indow_and_granularity__plan0_optimized.sql | 26 +- ...fset_window_and_offset_to_grain__plan0.sql | 514 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 34 +- ...offset_to_grain_and_granularity__plan0.sql | 526 ++++---- ...grain_and_granularity__plan0_optimized.sql | 36 +- ...h_offset_window_and_time_filter__plan0.sql | 262 ++-- ...indow_and_time_filter__plan0_optimized.sql | 28 +- ...erived_offset_cumulative_metric__plan0.sql | 56 +- ...set_cumulative_metric__plan0_optimized.sql | 20 +- ...offset_metric_with_agg_time_dim__plan0.sql | 284 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 20 +- ...et_metric_with_one_input_metric__plan0.sql | 56 +- ...with_one_input_metric__plan0_optimized.sql | 12 +- ...d_where_constraint_not_selected__plan0.sql | 122 +- ...nstraint_not_selected__plan0_optimized.sql | 30 +- ...h_offset_multiple_input_metrics__plan0.sql | 270 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 28 +- .../BigQuery/test_nested_offsets__plan0.sql | 98 +- .../test_nested_offsets__plan0_optimized.sql | 24 +- ...ed_offsets_with_time_constraint__plan0.sql | 106 +- ..._with_time_constraint__plan0_optimized.sql | 26 +- ...d_offsets_with_where_constraint__plan0.sql | 104 +- ...with_where_constraint__plan0_optimized.sql | 26 +- ...ry_have_different_granularities__plan0.sql | 262 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 84 +- ...ultiple_granularities__plan0_optimized.sql | 16 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 64 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 26 +- ...ry_have_different_granularities__plan0.sql | 686 +++++----- ...fferent_granularities__plan0_optimized.sql | 26 +- ...w_metric_multiple_granularities__plan0.sql | 332 ++--- ...ultiple_granularities__plan0_optimized.sql | 32 +- ...offset_window_with_agg_time_dim__plan0.sql | 64 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 26 +- ...set_metric_with_time_constraint__plan0.sql | 256 ++-- ..._with_time_constraint__plan0_optimized.sql | 14 +- ...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 +- .../Databricks/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 +- ...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 +- .../Postgres/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 +- ...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 +- .../Redshift/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 +- ...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 +- .../Snowflake/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 +- ...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 +- .../Trino/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 | 20 +- ...fill_nulls_for_one_input_metric__plan0.sql | 502 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 38 +- ...ine_with_filter_not_in_group_by__plan0.sql | 54 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 | 40 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 +- .../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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 +- .../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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 +- .../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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 +- .../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 | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...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 | 70 +- ...window_with_date_part__plan0_optimized.sql | 26 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 2 +- ...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 | 56 +- ...ffset_to_grain_metric__plan0_optimized.sql | 12 +- ...t_subdaily_offset_window_metric__plan0.sql | 56 +- ..._offset_window_metric__plan0_optimized.sql | 12 +- ...ily_time_constraint_with_metric__plan0.sql | 56 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 4 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 4 +- .../BigQuery/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 2 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 2 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Postgres/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Redshift/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Trino/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...spine_metric_predicate_pushdown__plan0.sql | 1102 ++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 84 +- ..._metric_with_query_time_filters__plan0.sql | 622 ++++----- ...th_query_time_filters__plan0_optimized.sql | 56 +- ...ine_pushdown_filter_application__plan0.sql | 50 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...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 +- ...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 +- ...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 +- ...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 +- ...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 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 2 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../Trino/test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../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 +- 756 files changed, 40761 insertions(+), 27009 deletions(-) create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index bdc55673da..ceb5b73c00 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: BigQuery --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS FLOAT64) / CAST(NULLIF(subq_20.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS FLOAT64) / CAST(NULLIF(subq_22.visits, 0) AS FLOAT64) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 , GENERATE_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 > DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 7 day) + subq_10.metric_time__day > DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 7 day) ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY metric_time__day - ) subq_16 + ) 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 metric_time__day -) subq_20 +) subq_22 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/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/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index c29b49ee48..04e97e0af2 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/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/BigQuery/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 + 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 + 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 + 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 , GENERATE_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 > DATE_SUB(CAST(subq_32.metric_time__day AS DATETIME), INTERVAL 7 day) + sma_28019_cte.metric_time__day > DATE_SUB(CAST(subq_35.metric_time__day AS DATETIME), 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 + 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 metric_time__day -) subq_40 +) subq_44 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 618e405f07..a13eea2d30 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 , 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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Databricks/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/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 054eabc223..388b9302b7 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/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/Databricks/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 + 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 + 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 + 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 , 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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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 + 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/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 47de6c7fea..a165cce374 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Postgres --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE PRECISION) 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 + 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 + 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 - MAKE_INTERVAL(days => 7) + subq_10.metric_time__day > subq_13.metric_time__day - MAKE_INTERVAL(days => 7) ) ) - ) 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/Postgres/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/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index ed86788422..cd6c238dc3 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/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/Postgres/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 + 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 + 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 + 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 - MAKE_INTERVAL(days => 7) + sma_28019_cte.metric_time__day > subq_35.metric_time__day - MAKE_INTERVAL(days => 7) ) ) - ) subq_33 + ) subq_36 GROUP BY metric_time__day - ) subq_36 + ) subq_39 ON - subq_38.ds = subq_36.metric_time__day - ) subq_39 + 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/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index a6ad786a7b..ce8c95d21f 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Redshift --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE PRECISION) 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) 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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Redshift/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/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 3c41d84dcb..b7de22a306 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/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/Redshift/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 + 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 + 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 + 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 , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) 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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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 + 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/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 83fdc354a2..dbab4f915e 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 , UUID_STRING() 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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Snowflake/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/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 463efd3a56..3e17a6cacb 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/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/Snowflake/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 + 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 + 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 + 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 , UUID_STRING() 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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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 + 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/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 10cab4b4e1..a393737960 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 , 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 > DATE_ADD('day', -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATE_ADD('day', -7, subq_13.metric_time__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/Trino/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/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index b354a8d965..9224c66d0e 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/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/Trino/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 + 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 + 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 + 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 , 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 > DATE_ADD('day', -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATE_ADD('day', -7, subq_35.metric_time__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 + 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_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql index 01f3d2d54b..5e36506556 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_8.ds, month) AS booking__ds__month - , subq_8.ds AS metric_time__day - , DATETIME_TRUNC(subq_8.ds, isoweek) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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,10 +403,10 @@ FROM ( , 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 booking__ds__month , metric_time__week diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql index 76197cdbcc..2773539027 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -27,38 +27,38 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATETIME_TRUNC(subq_20.ds, month) AS booking__ds__month - , subq_20.ds AS metric_time__day - , DATETIME_TRUNC(subq_20.ds, isoweek) AS metric_time__week - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + DATETIME_TRUNC(time_spine_src_28006.ds, month) AS booking__ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS metric_time__week + , 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 - DATETIME_TRUNC(subq_15.ds, month) AS booking__ds__month - , subq_15.ds AS metric_time__day - , DATETIME_TRUNC(subq_15.ds, isoweek) AS metric_time__week + DATETIME_TRUNC(subq_16.ds, month) AS booking__ds__month + , subq_16.ds AS metric_time__day + , DATETIME_TRUNC(subq_16.ds, isoweek) 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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_16.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 2 day) ) GROUP BY booking__ds__month , metric_time__day , metric_time__week - ) subq_18 + ) subq_19 ON - subq_20.ds = subq_18.metric_time__day - ) subq_21 -) subq_23 + 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_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql index dc03b367c6..14e6ad1f22 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql index 4a16253b66..9a4804c24e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -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 + , 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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 + 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_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql index 70d14c500d..7855ed0cc0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql index 417844f92d..983a2828ca 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -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 + , 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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - MAKE_INTERVAL(days => 2) ) 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 + 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_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql index 941471bd80..261588764a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql index 5d172a21ac..48882b6b0c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -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 + , 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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 + 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_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql index 227ad2b2be..e40ad6f566 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql index d98ee20cf1..4a5e31a4fc 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -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 + , 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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 + 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_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql index f3f6aceedc..645ca4ee18 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql index aa9a15b723..86b0938c51 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -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 + , 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) > DATE_ADD('day', -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_16.ds) ) 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 + 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/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index f86e3584ba..e576bf10fb 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: BigQuery --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 GROUP BY metric_time__martian_day - ) subq_5 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,5 @@ FROM ( metric_time__martian_day ) subq_4 ON - subq_5.metric_time__martian_day = subq_4.metric_time__martian_day -) subq_7 + subq_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 0f8e2275d2..df7653b706 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: BigQuery -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT 1 AS bookings , DATETIME_TRUNC(ds, day) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY metric_time__martian_day -) subq_12 +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..9df0548b6c --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..ad79ec6c63 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , DATETIME_TRUNC(ds, day) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..1835fbe78b --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..65ebc1691c --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , DATETIME_TRUNC(ds, day) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index f2bd1bad0c..0462e6897f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 0ab8123cd8..f9299a4fc6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATETIME_TRUNC(users_ds_source_src_28000.bio_added_ts, month) AS user__bio_added_ts__month - , DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATETIME_TRUNC(time_spine_src_28006.ds, day) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql index 059eed6836..b1ef40cf6d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index c79e24f131..d0ad89a1c0 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATETIME_TRUNC(time_spine_src_28006.ds, day) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql index 26d09dbf61..b22148bbe1 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.booking__ds__day AS DATETIME), INTERVAL 5 day) = subq_1.booking__ds__day + DATE_SUB(CAST(subq_4.booking__ds__day AS DATETIME), 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 booking__ds__martian_day - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql index ac6a6b2162..56fd02c5dc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_SUB(CAST(subq_12.ds AS DATETIME), INTERVAL 5 day) = subq_10.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 + time_spine_src_28006.ds = subq_15.ds GROUP BY booking__ds__martian_day -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 5f8af4c9a3..861a34a3f4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_8 -) subq_9 + ) subq_9 +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 4239dbf288..c2d381e942 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_12 ON - DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 5 day) = subq_11.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 + 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_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 9f446138a9..b3ecbb0e14 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Databricks --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index aca2005c25..58bb0498a0 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Databricks -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..38d5c37007 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..378bc1f4fc --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..33f4bfdf80 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..6d212f73db --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index da4f20ce6a..ebd4ec9d5f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 91a4d3a5c0..5e6182ae61 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql index 3afa45323a..b058c8129c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 510f4fce1d..4b117f7c87 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql index 11069c83b1..b2f6b57be4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql index cc3c8aeff5..b083f7d8fd 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 2b8e2f9a4c..e5a162f6a8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e4cb94adb0..f72023cccd 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 45d2f66892..6cd8c0d18f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Postgres --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 8387f5d46b..6a530c9c51 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Postgres -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..a1a508c5f1 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..1861779235 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..30af36cdf1 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..ca3faae77b --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index 08fb093ca4..0d67edcdf8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index f456f17c1d..653f324f95 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql index a4f123600d..95ba609d92 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index f881ddc13d..380aa8983d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql index d044519a28..e936a34491 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.booking__ds__day + subq_4.booking__ds__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 1a03d0f71a..7a645df17d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_10.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 + 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/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 31ea2c71a5..6c549bd201 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e5cb95f9b5..8e795d4a4e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 5) = subq_11.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 + 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_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index d8f039452c..d554b12ac7 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Redshift --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index bbf4df3583..b1e1028070 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Redshift -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..ec24e4a85a --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..aca8b6dc0b --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..a51ff93189 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..b9fd40d62c --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index f0cd2b74f9..1a4710abab 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 4448310b10..1bc0258fc5 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql index 12f9a80c41..22b6d8988f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 302c60ffb7..8fdfeeaffa 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql index 77805a6fd5..5a0632c108 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 70b91bc6a4..6e0433144c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index a98f058032..3f5bbf4ece 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 40e9bafc5b..c5b00d5129 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 4826683920..0e61d72ab6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Snowflake --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 2cfb7a831c..45e33d34c8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Snowflake -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..79ab9ff4a2 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..7fa69b2bb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..bad5991053 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..eb76773d90 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index 4cef563665..57bc6b1202 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 961e69d45d..139e5479a5 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql index b823b8b6f6..e06791c752 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 407b07dfa0..68d6d40cbb 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql index f1f3de76b5..22ba10b0c7 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 8d106e8686..1ee62fa020 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 520ce10b3d..8f68c4e825 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e86c0510f4..758c9edb49 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 + 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_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 071d9ac486..fe372816b0 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Trino --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.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_7.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_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,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_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 12a7b8a95f..df57011426 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Trino -- 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_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 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_10.martian_day AS metric_time__martian_day + , SUM(subq_9.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_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..8ec6ee8dd7 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..645afa1392 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..92cbcf1246 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..bdc4b3ed17 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index a560f03bda..121db942f8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 3af119502d..90640bb4d6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql index ebf291021e..fe81fe2961 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index abe4c357bd..9fee5399e2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql index 569610a235..658b8c5cfc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATE_ADD('day', -5, subq_4.booking__ds__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/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 4ab73ec738..3a83a25a26 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_12.ds) = subq_10.booking__ds__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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 + 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/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index a4430ef8ce..28ef9d1664 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATE_ADD('day', -5, subq_4.metric_time__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/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 2ed4e1008f..c161c74c5d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -5, subq_13.ds) = subq_11.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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 + 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_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index cb500cc780..3d87381b96 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_5.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_10 -) subq_11 + ) subq_11 +) subq_12 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index fd4d509af1..3b28e6b430 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_16.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 2 day) ) - ) subq_16 + ) subq_17 ON - DATE_SUB(CAST(subq_18.ds AS DATETIME), INTERVAL 2 day) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY metric_time__day -) subq_23 +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index a8ff00ed4f..068de1d348 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_3.ds, month) 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 + time_spine_src_16006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_16006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_16006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_16006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_16006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_16006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_16006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 metric_time__month - ) subq_2 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -99,10 +121,10 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_SUB(CAST(subq_2.metric_time__month AS DATETIME), INTERVAL 1 month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__month AS DATETIME), INTERVAL 1 month) = subq_1.metric_time__month + ) subq_5 + ) subq_6 GROUP BY metric_time__month - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 9bad19fa75..d8e371247e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine time_spine_src_16006 GROUP BY metric_time__month - ) subq_10 + ) subq_13 INNER JOIN ***************************.fct_bookings_extended_monthly monthly_bookings_source_src_16000 ON - DATE_SUB(CAST(subq_10.metric_time__month AS DATETIME), INTERVAL 1 month) = DATETIME_TRUNC(monthly_bookings_source_src_16000.ds, month) + DATE_SUB(CAST(subq_13.metric_time__month AS DATETIME), INTERVAL 1 month) = DATETIME_TRUNC(monthly_bookings_source_src_16000.ds, month) GROUP BY metric_time__month -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql index 527d9d0a4a..c64e67df8f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.metric_time__day, month) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.metric_time__day, month) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_11 - ) subq_12 + ) 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 metric_time__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index a3b05090c8..7efbb828bf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.metric_time__day GROUP BY metric_time__day - ) subq_26 + ) 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 metric_time__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 6b8f5a9d66..031cde075e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] SELECT - subq_8.ds AS metric_time__day - , DATETIME_TRUNC(subq_8.ds, isoweek) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.metric_time__day, month) = subq_6.metric_time__day - WHERE subq_7.metric_time__week = subq_7.metric_time__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.metric_time__day, month) = subq_6.metric_time__day + WHERE subq_9.metric_time__week = subq_9.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__week - ) subq_11 - ) subq_12 + ) 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 metric_time__week -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 69b5a61e8d..7d375865c0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, isoweek) 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 - DATETIME_TRUNC(subq_22.ds, isoweek) AS metric_time__week - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.metric_time__day - WHERE DATETIME_TRUNC(subq_22.ds, isoweek) = subq_22.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) = time_spine_src_28006.ds GROUP BY metric_time__week - ) subq_26 + ) 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 metric_time__week -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql index d4a80aad46..de146d1fe9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_11 - ) subq_12 + ) 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 metric_time__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql index fa0b0ca3bc..a183fb5acf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__day - ) subq_26 + ) 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 metric_time__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 8d30776e8a..007c6e96da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] SELECT - subq_8.ds AS metric_time__day - , DATETIME_TRUNC(subq_8.ds, quarter) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__quarter - ) subq_11 - ) subq_12 + ) 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 metric_time__quarter -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index cc6350e6d2..a2f15818a7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, quarter) 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 - DATETIME_TRUNC(subq_22.ds, quarter) AS metric_time__quarter - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATETIME_TRUNC(time_spine_src_28006.ds, quarter) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__quarter - ) subq_26 + ) 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 metric_time__quarter -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index ec3e167f19..bb9d279e68 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 + ) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__day - ) subq_14 - ) subq_15 + ) 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 metric_time__day -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index a0e830b694..cf94a9661d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATETIME_TRUNC(subq_20.ds, month) = subq_18.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_20.metric_time__day GROUP BY metric_time__day - ) subq_24 + ) 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 1 month) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = subq_29.metric_time__day GROUP BY metric_time__day - ) subq_32 + ) 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 metric_time__day -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 1a2e246f67..af1c06d02d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATETIME_TRUNC(subq_3.ds, year) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - WHERE subq_2.metric_time__year = subq_2.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + WHERE subq_4.metric_time__year = subq_4.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__year - ) subq_6 - ) subq_7 + ) 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] SELECT - subq_11.ds AS metric_time__day - , DATETIME_TRUNC(subq_11.ds, year) AS metric_time__year - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__year - ) subq_14 - ) subq_15 + ) 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 metric_time__year -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 8f7ccace52..6c87cda873 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/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 - DATETIME_TRUNC(subq_20.ds, year) AS metric_time__year - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATETIME_TRUNC(subq_20.ds, month) = subq_18.metric_time__day - WHERE DATETIME_TRUNC(subq_20.ds, year) = subq_20.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_20.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, year) = time_spine_src_28006.ds GROUP BY metric_time__year - ) subq_24 + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATETIME_TRUNC(subq_28.ds, year) AS metric_time__year - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 1 month) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = subq_29.metric_time__day GROUP BY metric_time__year - ) subq_32 + ) 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 metric_time__year -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index f2749ad4ac..7385ebc30e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_8.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_7.metric_time__day - ) subq_10 + DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_13 - ) subq_14 + ) 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 metric_time__day -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 5fc91ceab3..bb75d4d6f9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_25.ds AS DATETIME), INTERVAL 14 day) = subq_23.metric_time__day - ) subq_26 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 metric_time__day -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql index 06985ad46c..535e2668fd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_5.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_4.metric_time__day + ) subq_8 + ) subq_9 GROUP BY metric_time__day - ) subq_9 -) subq_10 + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql index b66ab403f2..400b3fa431 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_14.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_14.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) ) - ) subq_15 + ) subq_16 ON - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 2 day) = subq_15.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_16.metric_time__day GROUP BY metric_time__day -) subq_21 +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 2d791b43a7..b50ba9bcb1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.booking__ds__day AS DATETIME), INTERVAL 1 week) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.booking__ds__day AS DATETIME), INTERVAL 1 week) = subq_1.booking__ds__day + ) subq_5 + ) subq_6 GROUP BY booking__ds__day - ) subq_6 - ) subq_7 + ) 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 booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 3e333677d4..179d1ed98a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) GROUP BY booking__ds__day - ) subq_21 + ) 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 booking__ds__day - ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql index 58fb1dddbd..12f14d3b05 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index fcc4c15019..63ebed0c41 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_SUB(CAST(subq_11.ds AS DATETIME), INTERVAL 5 day) = subq_9.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_10.metric_time__day GROUP BY metric_time__day -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 4a81cecb71..715959da93 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day - ) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 14f557c69d..95f6f4f23e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_17.metric_time__day GROUP BY metric_time__day , booking__is_instant - ) subq_21 - ) subq_22 + ) subq_24 + ) subq_25 ON - DATE_SUB(CAST(subq_24.ds AS DATETIME), INTERVAL 2 day) = subq_22.metric_time__day - ) subq_25 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 1e108238eb..de831535bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_6.metric_time__day, month) = subq_5.metric_time__day - ) subq_8 + DATETIME_TRUNC(subq_8.metric_time__day, month) = 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 metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + ) 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 metric_time__day -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 07eb7ffae8..db075ed7a6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 metric_time__day - ) subq_20 - ) subq_21 + ) subq_21 + ) subq_22 ON - DATETIME_TRUNC(subq_23.ds, month) = subq_21.metric_time__day - ) subq_24 + DATETIME_TRUNC(time_spine_src_28006.ds, month) = 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 metric_time__day - ) 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 metric_time__day -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql index 04e0bb15f3..ef9272fb0c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day -) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql index 14d59bc467..6af166cd3e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_15 ON - DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 5 day) = subq_13.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day GROUP BY metric_time__day - ) subq_19 - ) subq_20 + ) subq_22 + ) subq_23 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 2 day) = subq_20.metric_time__day -) subq_23 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql index 3c020e799b..019f1565bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 4183500d03..0f735319da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 5 day) = subq_14.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day - ) subq_20 - ) subq_21 + ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_23.ds AS DATETIME), INTERVAL 2 day) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day + WHERE 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/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql index bc4faccfda..a10b0fac82 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day - ) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 974fba1880..46d5423668 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 5 day) = subq_14.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day - ) subq_20 - ) subq_21 + ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_23.ds AS DATETIME), INTERVAL 2 day) = subq_21.metric_time__day - ) subq_24 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 1393c92843..fea5eb2a61 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: BigQuery --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] SELECT - subq_3.ds AS metric_time__day - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - WHERE subq_2.metric_time__month = subq_2.metric_time__day - ) subq_4 + DATETIME_TRUNC(subq_4.metric_time__day, month) = 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 metric_time__month - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 9b21410866..3aa8c518de 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_12.ds, month) AS metric_time__month - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month + , 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATETIME_TRUNC(subq_12.ds, month) = subq_10.metric_time__day - WHERE DATETIME_TRUNC(subq_12.ds, month) = subq_12.ds - ) subq_13 + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_11.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, month) = 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/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 6adab29d6b..03586ac35d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: BigQuery --- -- 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__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_3.ds, year) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 039f084b2c..d40e57e9aa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_11.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_11.ds, year) AS metric_time__year - , SUM(subq_9.bookings) AS bookings_start_of_month - FROM ***************************.mf_time_spine subq_11 + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATETIME_TRUNC(subq_11.ds, month) = subq_9.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_10.metric_time__day GROUP BY metric_time__day , metric_time__month , metric_time__year -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql index c05bb94edb..14a79cfa64 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.booking__ds__day, month) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.booking__ds__day, month) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index fb74605744..ebf08d82ae 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 + 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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.booking__ds__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.booking__ds__day GROUP BY booking__ds__day - ) subq_26 + ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index e5b6bdae73..b72047f3e9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: BigQuery --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] SELECT - subq_3.ds AS metric_time__day - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day - ) subq_4 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__month - ) subq_7 - ) subq_8 + ) 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 metric_time__month - ) subq_13 - ) subq_14 + ) 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 metric_time__month -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 73536fe94b..74db443df6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_19.ds, month) AS metric_time__month + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month , 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 - DATE_SUB(CAST(subq_19.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) - ) subq_20 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + ) 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 ( , DATETIME_TRUNC(ds, month) 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 metric_time__month -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql index 5e4750080c..dce20780a7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: BigQuery --- -- 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__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_3.ds, year) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_6 - ) subq_7 + ) 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 metric_time__day , metric_time__month , metric_time__year - ) subq_11 - ) subq_12 + ) 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 metric_time__day , metric_time__month , metric_time__year -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index a913e59a6b..17b2bfbc1c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_17.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_17.ds, year) AS metric_time__year + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_21 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -54,17 +54,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) 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 metric_time__day , metric_time__month , metric_time__year -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql index d5a8ac8ec6..2eeeebc28d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_7.booking__ds__day AS DATETIME), INTERVAL 14 day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.booking__ds__day AS DATETIME), INTERVAL 14 day) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 201002c96a..b0e2c3491d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 + 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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.booking__ds__day GROUP BY booking__ds__day - ) subq_26 + ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql index 0e9e30db37..c0dbb90fb8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 3bc29dc98f..423c4e1150 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_SUB(CAST(subq_12.ds AS DATETIME), INTERVAL 5 day) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY metric_time__day -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 850c8a2464..04f145bdf7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index 8324d90b8b..4637576848 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 3dabd090e3..e0af5e59fb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 8dca633791..961743f33c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql index 134685c6ee..c428753d62 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 1e504f0202..99028cc6ca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index f09d32e7ed..663e1a38b0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 0422c77451..33f035ee73 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql index 16136ee1f8..dbe1b78aa5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql index cf81e784d1..1b8ce9efe5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 5bf84c68da..5ae5a0cfa0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index f38cb7d2b9..16bd08a0c5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 5d7d7aa3ea..03fa20d244 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index be9642ae8d..bd55d23baf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 011efcbf1e..c2b0043f36 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Databricks/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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 55bf083f45..1867dd46ae 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 10dc33073b..14b1115c08 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index f5faf4483c..67723dbb6d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql index 636ea606b5..0aad53b978 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql index 46f8a04db2..ee2e66dceb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 88b69a224f..15a1d9274c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 78ae26a9ed..e0d84b6dbe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql index f9d8141ddf..a4aae294c6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index ef9112432e..a466307d41 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 8d0f382179..6a93ac55d8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 6e2e83b479..89bcc32f7b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index e8867090be..721bb6fbad 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 3c7b7bd4bd..9803cab011 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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', 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/Databricks/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql index 2a162caea8..161b491043 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql index afed1816e7..9aec36d400 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql index 2b0efba5c2..7b18790e85 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 8b3aac867a..837d11c0c1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE 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/Databricks/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql index 4492ea2f39..44df912e8e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql index ec6b4352f0..7f46354fce 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 47a841cb29..f92202ef85 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Databricks --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index a45feb0355..8951bbe9e9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 976e8404a5..cca0e2f84b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Databricks --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 5b6603fdff..34497b505f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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', 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 + 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/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql index 62cf1b2253..ca3c4ba8f7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index c76a35a7af..9ab53f709e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index decfdb0bec..466fa889c0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Databricks --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 0acbd8cac9..3b39350ffc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql index 151fbd171c..ff2d3d11fb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Databricks --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 6d98d432d7..d4c2b8ec7f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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 + 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/Databricks/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql index 737cfa0f14..66bd074019 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 38008ad1e4..403b51d554 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql index 9440ae12f9..99631e191c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 92a8d09760..93a5ebbb6b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 657ae62d6f..b6f6922d4c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 2) = 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 - MAKE_INTERVAL(days => 2) = 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/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c035b82ddb..7bdf364b90 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - MAKE_INTERVAL(days => 2) ) - ) subq_16 + ) subq_17 ON - subq_18.ds - MAKE_INTERVAL(days => 2) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 4e96546efe..e85d050b43 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(months => 1) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + subq_4.metric_time__month - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 34b51248ac..fa50f3881c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(months => 1) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + subq_13.metric_time__month - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql index 783a3b9c02..6d326e0383 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index ece4b86e47..6e76fc93f9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 57f3a81974..e67ed0bf72 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 32cb49a8ee..0cb63ea030 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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/Postgres/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql index 612cd1565e..584ab1d270 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql index 9e88eaf124..0846df3c86 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql index a3c11f6528..5560daee9f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 53a9fe09c8..7140e9168a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 0d51482767..0603a435ba 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(months => 1) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 97deaf2d85..877e428105 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 - MAKE_INTERVAL(months => 1) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 834c12c2f5..e5bee98dfb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 - MAKE_INTERVAL(months => 1) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(months => 1) = 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/Postgres/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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index d5a61f7a89..f2b523f0be 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 - MAKE_INTERVAL(months => 1) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 69c1c7eeb0..6f7dd004c4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 14) = subq_7.metric_time__day - ) subq_10 + subq_10.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 2f0e94a1b2..7a86dcc467 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 14) = subq_23.metric_time__day - ) subq_26 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql index ef5e72141a..d2769c6a2b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 2) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + subq_7.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql index 1329a0ade5..3971271456 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - MAKE_INTERVAL(days => 2) ) - ) subq_15 + ) subq_16 ON - subq_17.ds - MAKE_INTERVAL(days => 2) = subq_15.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 49d2b87f02..b1054a07b5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(weeks => 1) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + subq_4.booking__ds__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 2f6371d3fe..334eb347a1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql index 23f3c3659d..d4b8eb0b37 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 814f94c4a2..715adafa67 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 5) = subq_9.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index e905ef7773..2e5d8fd782 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index c11fef9c79..cd6a43d881 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_15.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - subq_24.ds - MAKE_INTERVAL(days => 2) = subq_22.metric_time__day - ) subq_25 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 84366e4d4d..7b9c96bc80 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 2f8d1a2c5c..ea13211dfc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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', 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/Postgres/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql index 0cbb871dd0..f504a248c3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day -) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql index ba241866de..0cf2bf2811 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_13.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - subq_22.ds - MAKE_INTERVAL(days => 2) = subq_20.metric_time__day -) subq_23 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql index 37735affcc..56a0c6ffed 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = 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 - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql index ad70412fd9..47a6aadd20 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_14.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - MAKE_INTERVAL(days => 2) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day + WHERE 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/Postgres/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql index b842031313..c91a63071e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 0aa067052a..52405830a7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 - MAKE_INTERVAL(days => 5) = subq_14.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - MAKE_INTERVAL(days => 2) = subq_21.metric_time__day - ) subq_24 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = 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/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 743886eea4..352f9581db 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Postgres --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 52f737090e..6bc6a33365 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql index b4ff6725dc..a8d7c25962 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Postgres --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 321cb4ac6d..bb00b76d51 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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', 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 + 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/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql index d80383f1b1..aecfd7e330 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index e102ca8708..aa15d6d623 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 873e4a30d7..ed7b7f3c30 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Postgres --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day - ) subq_4 + subq_4.metric_time__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 3934f7c7ba..e6c54c903f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql index c38d5049a3..a0378db4c0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Postgres --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 34c12c7bd7..cd44a509e4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = 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 + 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/Postgres/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql index 9e29382368..c394be5984 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 14) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + subq_9.booking__ds__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 9d3549dd51..da8dd9be7f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 14) = subq_20.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql index 6d0b707805..96be1c4ae2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 5) = 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/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 773cb85a3d..1f8335e0a9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 5) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 9b22b1037a..b40be0e25f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index 54fdaf9388..bbaf908dcd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index d16d4843a7..d310236c96 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_16006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_16006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_16006.ds) END 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 9b19e89dbe..2d2800da42 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql index c299b86a8a..c3f5df6b50 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 464cffe605..5c7d16d46f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index e956f057e5..ca7a5e5579 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index d9147b7bdb..33677b9b06 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql index aad61e85c8..2d84352f95 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql index cfa62f92ad..f5ce56a3ca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 52e6be646e..6efb4d5716 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index b6bc0d71d8..cc4faaa112 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index d30aaa07eb..57bfed7c7b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index f23d4f512a..b427c8b0d2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index c0ffbc4b6e..8a73b7b632 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Redshift/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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index c0e2a731ed..0a65fe952d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 511363bfcf..3e0a8be65a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 3986620849..cc4d410ae7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql index c1818c710a..56d6747cf3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql index 28071a31e6..95d7828347 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 6932f490e2..87480251da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 67fe080a8b..4ed8e2a49f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql index b93df27b75..e56ffec816 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 6b9a08d0b2..e488fdb3f9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 9eb7ee2063..b6c41e3360 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 606a9fa315..e2a58e9666 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 77c4a6146a..e8ac67205e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 38559a01ae..6950c8a6a8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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', 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/Redshift/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql index 77928c9c0e..9f2e2553da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql index 858599a4b1..78c6b87a94 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql index 6619dd6f25..f906b5884d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql index a0cd96d15d..abff7fdb59 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE 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/Redshift/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql index b2226271d2..c8fceb70b8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 3d6418dab3..b75545623c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 1042220d4c..6cffa81f1d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Redshift --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index e2ef45757b..6877e3ae67 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql index a88c011d0d..b454a6bc9b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Redshift --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index e47d7558aa..778cb9215a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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', 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 + 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/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql index fcd1867942..f2dbceb180 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 3aefd9bee6..ed4b519e94 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index d292518132..d7c96e7ebe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Redshift --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 2608a60bae..7d3273439e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql index 8d3d0df119..68aaf926fd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Redshift --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 22753736dd..fe772da492 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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 + 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/Redshift/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql index d6994b9aa2..1ae85f2d33 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql index c0f2748032..10dcb076de 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql index 9ff738e788..efab319dbb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index eb8f6a54d0..ab218ad8f9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 6a112a6e5b..f21741074b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index f20bb5198f..5929f7bc2f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index b1c9634d3a..67bfb650e5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 198624f2fc..4b63f35ac7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql index 8c9de2b854..4bf050c361 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index f61138cd39..4027bad0cf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 093d19c38d..0f27bed4b3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 9d2b8b9ae0..d23d8d8f65 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql index 7217c53603..bc98461959 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql index ce55aa2953..de25cf3175 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 2fb4b0f8cb..7f66709296 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 8b3679742b..bc333100d3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 9b94279745..d6346015de 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index a19241a8b9..ae8d090a2d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index ddf8b95558..7bf8837ad2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Snowflake/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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index b8eb112e70..ac32f48672 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index e8efb7582a..715014b274 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index f8f10fb732..35eaf9c55f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql index a0c24f4ad8..4e004941e7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql index 3776496f57..daf33313bf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 5414acdf40..bc31285d00 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 88b862779c..20244a5160 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql index 460c155b07..070226546a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index a603ed6aaf..915d96de67 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 0d33e40462..20fd7b6cf4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 9388c1fcc3..be9fa2df7a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index afbe9604b6..1f475b6148 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 58da2a3cca..f8b59c4004 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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', 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/Snowflake/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql index dde312e101..9970d15e37 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql index f750dc6487..b21ee2333a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql index 4b8fa3ee3a..c4fb439efc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 68d9df1848..96fb239f13 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE 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/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql index 0942c73ff9..90dec6ff38 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql index d23fbf4a14..1b0f2830a4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 43431536dc..c011099a7f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Snowflake --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 2fec95707b..39d096eebf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql index d01f96513f..ad31de3413 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Snowflake --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(dayofweekiso 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/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index d270f22808..44ec893a1e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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', 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 + 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/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql index cb56bf5553..20fb82cd86 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index cc5e1978fc..0a55ccb194 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 38eae4d798..ac218aeab3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Snowflake --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 28159c1513..018f4f4d95 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql index c6bfc372c3..4c8364ec42 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Snowflake --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 1e34609202..3e5304e11d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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 + 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/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql index 8637158587..9220f0cf76 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql index bc37fe7312..d05ce796bc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql index 131df56136..d9860cc30f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index ca27d77027..9e7c4ff455 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index c2f529376d..f77f413eb7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' - ) subq_8 - ) subq_9 + DATE_ADD('day', -2, subq_7.metric_time__day) = subq_4.metric_time__day + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '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/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c74bc63f1d..e3963f89f6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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) > DATE_ADD('day', -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATE_ADD('day', -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 782826cc2b..86337ecbab 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATE_ADD('month', -1, subq_4.metric_time__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/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 7a98c4a7dd..276368a24b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATE_ADD('month', -1, subq_13.metric_time__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/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql index 252cd8290d..511b7c6ef1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 7c14527adb..420d8ac043 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 25ee9554a8..50403bd895 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , 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__day', 'metric_time__week'] 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__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 20579c6291..5cf1cb51b5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index 92809b655f..8d3e6cb0ef 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, 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/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql index 97562a5c6a..d64a1c891c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + 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/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 55707852fe..41e01022ac 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , 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__day', 'metric_time__quarter'] 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__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, subq_9.metric_time__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/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index a92f248822..92b9993423 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 07820dc20b..67fa1029c6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('month', -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 320c34869a..e04652fa89 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + 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 + 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 - DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 1388092eb8..226dc4aaf7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , 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__day', 'metric_time__year'] 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__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , 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__year'] 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__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('month', -1, subq_13.metric_time__day) = 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/Trino/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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 376523e669..ca4be6f1b6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/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', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = 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 - DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 6cd2eb1c48..b16c7e1b70 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATE_ADD('day', -14, subq_10.metric_time__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/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index deaef78743..98a41b885f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index 6d72a2d186..f1e3f4f3bb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATE_ADD('day', -2, subq_7.metric_time__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/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql index c9431a6e52..0838604a60 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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) > DATE_ADD('day', -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATE_ADD('day', -2, subq_17.ds) = subq_15.metric_time__day + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 128caed9bb..87076100ad 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATE_ADD('week', -1, subq_4.booking__ds__day) = 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/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index bf41617483..4cbcf8999a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('week', -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_ADD('week', -1, time_spine_src_28006.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + 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/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index 3005aefe06..e1da184c12 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index bb78d05bf8..cd55e4b0da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -5, subq_11.ds) = subq_9.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 72065e71c3..b47f0d4a21 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, subq_4.metric_time__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 - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__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/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 8adb624ace..01dab6b8e5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 - DATE_ADD('day', -5, subq_17.ds) = subq_15.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - DATE_ADD('day', -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATE_ADD('day', -2, time_spine_src_28006.ds) = 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/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 761d599285..5ef8622208 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 0694bbdbd3..3496289cd4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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', 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/Trino/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql index 81b96798ce..4a30deed49 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql index 02db30d704..e59300d868 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 - DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATE_ADD('day', -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql index 2a720cd404..9d45ea8f01 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' -) subq_12 + DATE_ADD('day', -2, subq_12.metric_time__day) = subq_9.metric_time__day + ) subq_13 + WHERE subq_13.metric_time__day BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 8bb73428b0..b3018cd737 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 - DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' -) subq_25 + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql index c077b8eaf2..890d1bbd53 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__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/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql index eda2cec264..38d6d2753d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 - DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATE_ADD('day', -2, time_spine_src_28006.ds) = 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/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 8bbd7d99dd..97f3779565 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Trino --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 600f39647f..551977838f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , 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', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = 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/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 3f7983fed3..f5b1c831d1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Trino --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 88c1ed0b75..e59051e4a3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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', 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 + 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/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql index 47acb13a2e..bad58df502 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 9f5c75d844..f27304c359 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index dd9bb9335a..7698997fe5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Trino --- -- 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__day + , subq_5.metric_time__month + , 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__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , 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__day', 'metric_time__month'] 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__day + , subq_3.metric_time__month + 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__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATE_ADD('week', -1, subq_4.metric_time__day) = 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/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index c2acb88017..ee39d66535 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , 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 - DATE_ADD('week', -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATE_ADD('week', -1, time_spine_src_28006.ds) = 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/Trino/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql index 6f337acc8e..ecdb5d2caa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Trino --- -- 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__day', 'metric_time__month', 'metric_time__year'] 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('week', -1, 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 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/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 5111961e53..3eef121b74 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('week', -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_ADD('week', -1, time_spine_src_28006.ds) = 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 + 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/Trino/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql index b6d85b7bef..d25f34114b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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_ADD('day', -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, 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/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql index fe12cd0d68..215d49938c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.booking__ds__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + 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/Trino/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql index 0b6a48e463..185531ad66 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - WHERE subq_4.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' - ) subq_5 - ) subq_6 + DATE_ADD('day', -5, subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '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/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index db938122af..dee7544e93 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql index f1ab433c4e..d5c090650a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql index ff83eff861..170b5bf10b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_13.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_14.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_14.ds AS DATETIME), INTERVAL 2 day) ) GROUP BY metric_time__day - ) subq_16 + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 9fb6348b04..2d0012cd4c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__day - ) subq_14 - ) subq_15 + ) 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 metric_time__day -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 576edf2281..8e48b6f85f 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) 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 + 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 + 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 14 day) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_29.metric_time__day GROUP BY metric_time__day - ) subq_32 + ) 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 metric_time__day -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index f906547d3e..edbdec60b7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 61f5537d64..780968de77 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, month) 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 3b815691dd..2e117ea480 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index e70deef36f..200ad9e55b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, day) 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index e83de302ce..364ed58624 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/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: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 95caa9421e..71eb59eed8 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/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: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, day) 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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index a67b4d9f0b..5026646b1b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_6.ts, day) 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 metric_time__day - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -618,5 +640,5 @@ FROM ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index b069e9ae8e..cb1723dff5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: BigQuery -- 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 DATETIME_TRUNC(ts, day) AS metric_time__day , ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + 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 ( , DATETIME_TRUNC(archived_at, day) 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/BigQuery/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql index d33848a09e..ab0e79be2a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_7.ds, isoweek) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql index fc1d485a58..09344e1646 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 , DATETIME_TRUNC(ds, isoweek) 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 DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 91d79f1546..9d5e32da31 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 9cd507a222..ef18f2efa9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(ds, day) 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 + 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/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql index 1a838af28e..b5762cfa7e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_5.ds, month) 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 metric_time__month - ) subq_4 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -229,5 +251,5 @@ FROM ( 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/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 003a95adbf..25cebb7920 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__month - ) subq_11 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,10 +34,10 @@ FROM ( DATETIME_TRUNC(ds, month) 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_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql index 329939234c..8473d26b75 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql index f402f4015f..f005994591 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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 + 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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql index ff700c7982..457f4071de 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index ba9e282ecb..c21c695325 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 + 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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 4370282ae7..1fe8f50cb5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 2282acd201..015fa21272 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Databricks -- 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('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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 5356e33970..c11a194d4a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index d9f5ff9262..16a9cfd0b3 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Databricks -- 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('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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 73f9eb22d3..556cd50cf9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/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: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 43db701576..9fad967f9d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/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: Databricks -- 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('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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 8346be424c..76d1671536 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 304c800e44..734a97a237 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Databricks -- 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 + 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/Databricks/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql index f1d349a80d..94346b1be0 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql index 74c708c8ee..9fe01abdea 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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('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/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql index f2efd2d72d..c67a0a2e9a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 179c2b34b1..94ff4a4572 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql index 9d861ff6e5..49a07628d4 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index dedc11ff7c..903e89a6da 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql index 06958d27b0..052c50251e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql index 4881dd4607..40347e593c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - MAKE_INTERVAL(days => 2) ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql index d39655e2e2..e803d95af7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Postgres --- -- 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 + 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 + 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 - MAKE_INTERVAL(days => 14) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 44671f8248..3647fb8fd6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 + 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 - MAKE_INTERVAL(days => 14) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 6e0794f61d..c28fe516ed 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index b4ad638e34..d92e57f3ed 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Postgres -- 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('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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 529aff654a..61ac714988 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 82aa6ba374..6d860edf75 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Postgres -- 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('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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index a08ad28212..02b86a76dc 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/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: Postgres --- -- 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 + 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 010c92bf29..7a1a8ef68c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/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: Postgres -- 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('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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index c304a7cbe8..378849d5b1 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index b305cd0dcf..9522db4e29 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Postgres -- 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 + 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/Postgres/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql index b6e2a39be8..f3539ad1a7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql index 1aa6ec229b..8038d13401 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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('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/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql index ee610ec2e3..0fdde58cdd 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index e5ad631c99..8ecb135bdb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql index 14cd08fddf..e08f96c336 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 7b2e9d7b67..bf2b71823c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql index f5848192ba..428122840a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql index cff38d699e..2288080050 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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 + 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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 07a40daab5..b75d08b2cc 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 25e33fd181..71aab401e8 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 + 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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 8774fd78d2..a51cb25345 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 0bf3b29076..bfa923a39d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Redshift -- 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('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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 121b170ef1..edae3b8d2c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 05d5c2c089..29dd3c5454 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Redshift -- 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('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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 9285d0f173..149ad4a8cc 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/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: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 13d7ad5eb7..59b9ec7788 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/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: Redshift -- 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('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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index c49a223f64..b99fdd742b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index bf3835d2b1..9b8badbb97 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Redshift -- 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 + 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/Redshift/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql index 9f9bde7590..79b072f188 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql index 9b9bd45b7f..49adb5a8cb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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('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/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 7a79937faa..5c2844da6c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 98fb58c9c0..36fc75aa17 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql index 737a0e9338..1d157eb6ee 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index c66e456507..28a1cbce35 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql index b940e505ec..6ab4f792db 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql index 3fc6b83ac2..86bc959f0a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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 + 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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql index aacf956181..066275fdc4 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 34a698d3f4..24cd1192ee 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 + 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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index e911843e27..786f1d06c7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index c3fbedd6ac..e693dcac86 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Snowflake -- 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('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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index dfe62f1d8a..9f82c13a53 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 8e361ce9cb..f80047dcfb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Snowflake -- 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('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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 79e86b2722..98dccdec71 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/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: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 10f573e607..df83ffd2cb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/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: Snowflake -- 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('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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index e71ef86638..2e734c2765 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 7cc83fd88c..d618361005 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Snowflake -- 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 + 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/Snowflake/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql index 8834fd78c4..a5a0dcbf68 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql index e943c194df..7eeca32ba9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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('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/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql index e52e911b8a..cc02c61baa 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index c1e9df5280..812595810a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql index 996ab626df..cbc6d0320a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 6f302a497c..b0f3f53f3f 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql index a96adb97ed..e83b8ee88a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql index 4d68df91c8..a737bf8337 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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 + 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) > DATE_ADD('day', -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_14.ds) ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + 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/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 812cafa17d..51fadf689b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('day', -14, subq_13.metric_time__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/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 45f332582e..bab6cbd6a6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 + 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 - DATE_ADD('day', -14, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + 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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 054ccef045..0c5fe4c9d5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 3dc708c76e..152ff7343c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Trino -- 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('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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 9a183f5ef6..513f3fe44d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 30f440d3c7..72bb8efe68 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Trino -- 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('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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 0e51c11f9f..cf8809654c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/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: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index d99e51e0f0..274e58e862 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/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: Trino -- 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('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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 0d0d478189..f4f6224713 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 3fc203f8d9..879d15f263 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Trino -- 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 + 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/Trino/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql index 3d8dc18017..72541bb033 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-03' AND timestamp '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 + 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(DAY_OF_WEEK 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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_10 + subq_10.metric_time__day = subq_5.metric_time__day + ) subq_11 + WHERE subq_11.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_12 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql index 588e8f1d19..4516d044aa 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_18 - WHERE ds BETWEEN timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_21 + subq_23.metric_time__day = subq_18.metric_time__day + WHERE subq_23.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_25 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql index e2adfda223..8509517a16 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 1d62fa0a8b..64a16a3301 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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/Trino/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql index 40c87b43fb..f727a57512 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index bf59616d75..981ca08291 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/BigQuery/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql index a505a20320..84cef61fe6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , IF(EXTRACT(dayofweek FROM subq_8.ds) = 1, 7, EXTRACT(dayofweek FROM subq_8.ds) - 1) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__extract_dow - ) subq_11 - ) subq_12 + ) 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 metric_time__extract_dow -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql index 6aad32a7f6..0e8ba946ff 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 ( IF(EXTRACT(dayofweek FROM ds) = 1, 7, EXTRACT(dayofweek FROM ds) - 1) 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 - IF(EXTRACT(dayofweek FROM subq_22.ds) = 1, 7, EXTRACT(dayofweek FROM subq_22.ds) - 1) AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__extract_dow - ) subq_26 + ) 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 metric_time__extract_dow -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql index 526a223b4a..f0e2100f1b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATETIME_TRUNC(time_spine_src_28002.ts, millisecond) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATETIME_TRUNC(time_spine_src_28002.ts, second) AS ts__second , DATETIME_TRUNC(time_spine_src_28002.ts, minute) AS ts__minute , DATETIME_TRUNC(time_spine_src_28002.ts, hour) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql index 5afa705853..01adc93d63 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: BigQuery -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATETIME_TRUNC(ts, millisecond) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY metric_time__millisecond diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index 6c1dc6ea59..532af83b4b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index f1ce4bf137..9780279b2f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 + 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 ( DATETIME_TRUNC(archived_at, hour) 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql index 4e7932a2d4..7ed08c9824 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 96e2502fd9..afb11ecd8c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 + 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 ( DATETIME_TRUNC(archived_at, hour) 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql index 8a5c568458..3e1c9a87a4 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__hour, hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__hour, hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY metric_time__hour - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 5a9219415d..bedcf0999d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(archived_at, hour) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATETIME_TRUNC(subq_11.ts, hour) = subq_9.metric_time__hour + DATETIME_TRUNC(time_spine_src_28005.ts, hour) = subq_10.metric_time__hour GROUP BY metric_time__hour -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql index 4f79f08a25..077be59644 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_2.metric_time__hour AS DATETIME), INTERVAL 1 hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__hour AS DATETIME), INTERVAL 1 hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY metric_time__hour - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql index 7997b120d8..9a21c21fee 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 + 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 ( DATETIME_TRUNC(archived_at, hour) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_SUB(CAST(subq_11.ts AS DATETIME), INTERVAL 1 hour) = subq_9.metric_time__hour + DATE_SUB(CAST(time_spine_src_28005.ts AS DATETIME), INTERVAL 1 hour) = subq_10.metric_time__hour GROUP BY metric_time__hour -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql index b2926769d6..0775cc2185 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28005.ts AS ts__hour + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index 49cdb09ec4..514d9cbbce 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: BigQuery -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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 DATETIME_TRUNC(archived_at, hour) 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_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql index 76ab641df5..d23120a10c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATETIME_TRUNC(time_spine_src_28003.ts, second) AS ts__second + time_spine_src_28003.ts AS ts__second , DATETIME_TRUNC(time_spine_src_28003.ts, minute) AS ts__minute , DATETIME_TRUNC(time_spine_src_28003.ts, hour) AS ts__hour , DATETIME_TRUNC(time_spine_src_28003.ts, day) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index bb805e7bb5..ce70571020 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: BigQuery -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATETIME_TRUNC(ts, second) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATETIME_TRUNC(ts, second) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY metric_time__second diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql index 78e5a822aa..3303dd9794 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , EXTRACT(DAYOFWEEK_ISO FROM subq_8.ds) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Databricks/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0_optimized.sql index fcbbcc1ba0..5b86d8479a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(DAYOFWEEK_ISO FROM subq_22.ds) - ) subq_26 + EXTRACT(DAYOFWEEK_ISO 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/Databricks/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql index 741feb6836..72f044094f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql index c630b8c5db..c9967312ae 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Databricks -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index 6f285dc40f..cd25724783 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index d0280d8ecd..5f3731d461 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql index 031c035f93..42b2dd4e18 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 95cde06772..cad51c6725 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql index cea3e05ee3..1b32002177 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index a2be431b34..45d51ea23b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql index be705a33d5..b2f7fd8b07 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql index 33ac7b7e64..7c292f8d43 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql index 037d6a95e7..301f1659c2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index dfce633cab..18f5a4f4a6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Databricks -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql index 072d4be07b..fae663a8cc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index c84265d19d..dbfb173c19 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Databricks -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql index 6d998a8f59..eb97d4d7a0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] 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__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0_optimized.sql index 5e0bf2bbcd..4aef7d64a2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql index 42256c457a..7d548d6772 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql index 3a7db9be7b..1b241ced5f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Postgres -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index d066a3acb1..c587f47796 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 07c19ae304..36cb00d7d9 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql index 4c9f57d85f..097eaf9623 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index e4ddf574a2..86db1791da 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql index 01c5d362aa..d28e2a7cdd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 4ebee052c5..4393ab1af0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql index 7423e9cecb..3bb4eeb2f9 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(hours => 1) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + subq_4.metric_time__hour - MAKE_INTERVAL(hours => 1) = 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/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql index 41dd8e3274..7975949ef7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(hours => 1) = subq_9.metric_time__hour + time_spine_src_28005.ts - MAKE_INTERVAL(hours => 1) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql index e47857efa1..578bfb625d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index db2603787a..325abee03f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Postgres -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql index c24d956102..e9c10cfcb7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index f7e83dfc42..dff63d8def 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Postgres -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql index ebc94261b2..6889b3d30e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , CASE WHEN EXTRACT(dow FROM subq_8.ds) = 0 THEN EXTRACT(dow FROM subq_8.ds) + 7 ELSE EXTRACT(dow FROM subq_8.ds) END AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Redshift/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0_optimized.sql index c2b6382245..fa2348d831 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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 ( CASE WHEN EXTRACT(dow FROM ds) = 0 THEN EXTRACT(dow FROM ds) + 7 ELSE EXTRACT(dow FROM ds) END 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 - CASE WHEN EXTRACT(dow FROM subq_22.ds) = 0 THEN EXTRACT(dow FROM subq_22.ds) + 7 ELSE EXTRACT(dow FROM subq_22.ds) END AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - CASE WHEN EXTRACT(dow FROM subq_22.ds) = 0 THEN EXTRACT(dow FROM subq_22.ds) + 7 ELSE EXTRACT(dow FROM subq_22.ds) END - ) subq_26 + CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END + ) 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/Redshift/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql index 70ee6f1104..8d45cb78dd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql index 0390430b2c..fb84f33250 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Redshift -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index f0c40272ea..d851163626 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 453237b4fd..6c82bf533d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql index 54b24c63a0..1d75d14895 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 0c0b432a25..602052f02d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql index 1ffc9288b3..7a4b358de7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 7b1ea188a2..8e7fb780f2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql index dec0c1f262..3e6befa2c8 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql index eeb440b35e..94c485ec0d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql index 720f5b5fcc..22a3fe7e63 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index ea228e49a5..0fb64ca196 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Redshift -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql index 83e45cba56..60c9294d3d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index 8d5f22e9ab..0ce2906c6d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Redshift -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql index 4bf8aa2ad0..613e8b9391 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , EXTRACT(dayofweekiso FROM subq_8.ds) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql index 656edaf9fe..cc38a3b197 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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(dayofweekiso 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(dayofweekiso FROM subq_22.ds) - ) subq_26 + EXTRACT(dayofweekiso 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/Snowflake/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql index f04969898e..a60843bb73 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql index 4115c35578..9ea914683c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Snowflake -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index f49b63940c..fa5860a89e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 2eeeed0e10..bfd447c99b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql index 886780f3c0..1944ca5da0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index df5043613f..5364ec0572 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql index 40a67cce56..4f56de7ebc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 0ac8b25258..c6434d88be 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql index eb88be7424..d9076f1cee 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql index 0ee8b61dbc..ec5df2185b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql index e4a5141670..86c83e484a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index bfbc3f9e21..4c22764192 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Snowflake -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) 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_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql index 6dae544669..01f30c25f5 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index ae3580bbd5..d485ef7038 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Snowflake -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 86d96b5a51..5ab1a267ba 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , 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__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , EXTRACT(DAY_OF_WEEK FROM subq_8.ds) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, subq_9.metric_time__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/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql index 4def88a76d..799bee05d1 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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(DAY_OF_WEEK 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(DAY_OF_WEEK FROM subq_22.ds) - ) subq_26 + EXTRACT(DAY_OF_WEEK 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/Trino/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql index 20b53144b6..adccf749f1 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql index b246c4a22a..01cc5609f8 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Trino -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index e641672210..6fa13ae01f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 5a6cc12574..085d354e27 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql index f0e67cd869..79955d227b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index ab20d4c194..1638287eec 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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 + 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 + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql index d5e95786d7..8b019179d7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 6eca0ddc3f..b47f0d671e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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 + 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', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql index fd5a04343d..2785ad7093 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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_ADD('hour', -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_ADD('hour', -1, 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/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql index f51d27ebec..cdf9770ccc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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 + 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_ADD('hour', -1, subq_11.ts) = subq_9.metric_time__hour + DATE_ADD('hour', -1, time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql index aab4b84e77..1bd23705a9 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-01 02:00:00' AND timestamp '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 + 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(DAY_OF_WEEK 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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' +) subq_10 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index 3b87095aeb..0d406c1d6d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Trino -- 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 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' -) subq_14 +) 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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' + subq_19.metric_time__hour = subq_15.metric_time__hour +WHERE subq_19.metric_time__hour BETWEEN timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql index 0ad00d294b..7075b2156d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index 6a8c7968f7..0edc9ed915 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Trino -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN timestamp '2020-01-01 00:00:02' AND timestamp '2020-01-01 00:00:08' +WHERE ts BETWEEN timestamp '2020-01-01 00:00:02' AND timestamp '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql index dd9c991acd..204fa0945b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql index 6d88dc1f18..f6afbb3b98 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: BigQuery -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,7 +16,7 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATETIME_TRUNC(time_spine_src_28006.ds, day) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY metric_time__day , listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql index 03f1e60d7b..db2e1ba1ee 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql index a28135efb1..9c583cd364 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: BigQuery -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql index 1e36bab5df..8f232846b8 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql index d417da1fad..7763a36b20 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql index a812644fa0..2087e24eb2 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: BigQuery -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql index 13d7fa7ffe..f67b139ba8 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql index 2cf42ce5da..6d943cc045 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Databricks -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql index 752986b2d5..df27d3f1c5 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql index 233227bf1d..5610747914 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Databricks -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql index 60cb8f349f..88745af888 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql index f3a1bdc2d2..a8a94d8497 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql index 9adb126699..b2c876e43e 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Databricks -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql index 9a32af4103..d2d6325aea 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql index 3ab1c2cd73..421b597cb0 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Postgres -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql index 9e6c0f4395..5dac369396 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql index d30aeb8ce6..ceee9d9577 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Postgres -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql index 02a2fbe206..34046690bf 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql index 82e33f4b08..e79d804b42 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql index 63d1ce8f6f..248ec8ab1d 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Postgres -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql index 86ad34143c..5ca4d4e687 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql index f0c7b115c4..c656e87b27 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Redshift -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql index 9a16e40191..196f557bac 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql index 35ee89b9ed..716a39e7b9 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Redshift -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql index b6be7d7c0e..fbdba485b6 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql index 48588917e2..6c1d358959 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql index 449918ddd7..096ee1c6c6 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Redshift -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql index 4892a897bc..b64d5e9ebc 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql index f61217729f..4cba1e7f84 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Snowflake -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql index ff8ad8419d..3f15fa6420 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql index edff68d5e6..0fb73d204a 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Snowflake -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql index d9ea85e51a..13fa2c8850 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql index e6303f3ba9..ef0c2368ac 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql index 8cc860f7f4..22ed9e9e6e 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Snowflake -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql index 1323d82a36..49e96f2ddf 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql index 63ccc44d05..682daba14d 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Trino -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql index f93f9fda87..dcdcb6c783 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql index 1a2575775e..9df66baf6b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Trino -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql index b17fa8e912..bbe069fe20 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql index 54cbee6aaa..ab7805e1e0 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql index 43d59ec971..3a295e45c7 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Trino -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index e3720fbdc2..973599f5de 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_15.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_14.metric_time__day - ) subq_17 + DATE_SUB(CAST(subq_18.metric_time__day AS DATETIME), 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 metric_time__day , listing__country_latest - ) subq_24 + ) 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 metric_time__day , listing__country_latest -) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index c0df4693cf..5eb5862303 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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 + 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 + 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 - DATE_SUB(CAST(subq_46.ds AS DATETIME), INTERVAL 14 day) = subq_44.metric_time__day - ) subq_47 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 + 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 metric_time__day , listing__country_latest -) subq_59 +) subq_65 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql index 61b8e67dfe..9671757b68 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_11.metric_time__day - ) subq_14 + DATE_SUB(CAST(subq_14.metric_time__day AS DATETIME), 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 metric_time__day , listing__country_latest - ) subq_21 - ) subq_22 + ) 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 metric_time__day , listing__country_latest -) subq_23 +) subq_24 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 649c633500..66680a7f0f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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 + 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 - DATE_SUB(CAST(subq_37.ds AS DATETIME), INTERVAL 14 day) = subq_35.metric_time__day - ) subq_38 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 metric_time__day , listing__country_latest -) subq_47 +) subq_49 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 216c2ec201..6c5ef49c47 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 2659e82a7b..9c9080de2a 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index f8a742f6d7..19f2a852cf 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 9daa5092a0..9585dfe018 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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 + 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 + 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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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 + 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/Databricks/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql index b13b34da59..936b1c6d13 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 3916fbc8d1..7d1e8f030e 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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 + 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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 95474dc021..0e4d63bd05 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 7d1ca9d50a..241b0cd730 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 45d6227836..77dbbe7388 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Postgres --- -- 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 + 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 + 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 + 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 - MAKE_INTERVAL(days => 14) = subq_14.metric_time__day - ) subq_17 + subq_18.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 15ac247a92..89a8543844 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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 + 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 + 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 - MAKE_INTERVAL(days => 14) = subq_44.metric_time__day - ) subq_47 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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 + 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/Postgres/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql index e2943612fa..eacf482d11 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Postgres --- -- 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 + 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 - MAKE_INTERVAL(days => 14) = subq_11.metric_time__day - ) subq_14 + subq_14.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 637b25a3f4..e1b2db56d6 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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 + 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 - MAKE_INTERVAL(days => 14) = subq_35.metric_time__day - ) subq_38 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index d357c66ea0..753078dbd0 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 8b30ca56e5..52dd1020a8 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 5cd70913b4..cf718556e4 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 26fd818dd1..419a35173f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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 + 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 + 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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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 + 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/Redshift/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql index 86c4b97d3f..0a3a244b83 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 360555b7ca..f821dafef9 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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 + 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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 1389f1d896..9c34bb6aff 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 0e86ce90f9..c893fefbc9 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 06d700d003..b445df3750 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 0910734c31..bbd2a1ba27 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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 + 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 + 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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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 + 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/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql index 58096f0e8a..9831db573d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 0fbcd96ac6..a8b170c4f7 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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 + 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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 8af26b0e96..f2e9ea2b96 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 9abfe0b08d..b9adcba9fa 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index f43548aff4..fe4df30518 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATE_ADD('day', -14, subq_18.metric_time__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/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 0a8042dc50..332fb030ef 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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 + 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 + 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 - DATE_ADD('day', -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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 + 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/Trino/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql index a0e2d67c17..ccfb347e59 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATE_ADD('day', -14, subq_14.metric_time__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/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 2187c07082..4a8cf474a0 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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 + 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 - DATE_ADD('day', -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index aeb65f982c..2da638870b 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index cc5b200f41..acd93ba336 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql index e63da94cef..c5a238d466 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql index f067853ff9..880ab8b587 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql @@ -13,7 +13,7 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql index 0a3b4a0875..99fb54f888 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql index fbc7d58b0f..68327fbec9 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql index 8dd1eb2e93..ed8ed107b0 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql index f3b44dc146..7b4f927116 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql index 4bc028bcb7..41e1db11dc 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql index 13f1bc8b96..e0c32113fc 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql index c6fef2e1e1..6144d5b142 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql index 1e33d21843..f03cc14a7f 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql index 6563a305b8..830a7f9a4a 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql index a178460301..709be0898c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql index 4d6e8b2832..d4cebb1bf8 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql index 70404201b8..4eccdb3cf8 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql index 09ba241b3c..e14f877769 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql index 2492a96933..ee9846830d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql index 5e802093db..9d4a93b540 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql index 89e34683d4..296bb6b2d6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 618a056455..834efd8d46 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 85b20c5d7c..6f698ad2fd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: BigQuery -- 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 + 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/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 06bdf58c3a..467211961b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index de3aa30c2b..4a4132f7e9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,11 +39,11 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql index f4b12a8d77..fe3495eb1e 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql index dc9cd55117..a9f0e04cf4 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 + 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 ( DATETIME_TRUNC(ds, day) 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql index 999f6c319b..0e0603623f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index c76f36ad90..1f7a1824dd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + 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/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 364344f673..c121e99dd5 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: BigQuery --- -- 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 + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 4bb4638cfb..e7f02ec47a 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index cd5b0f7415..ff9d01dd9d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 5990d18b17..c1a13571bd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Databricks -- 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 + 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/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 2309540a01..1bc52f2f4a 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 399086d226..cae1dcf11f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) 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/Databricks/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql index 8d1dba903a..6299600657 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql index e3aff697e8..375262c7f9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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 + 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql index cf0e7eb665..16a0e0c352 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index dc1e54c55b..b1b4d38fab 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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 + 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 + 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/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index e7188d22d5..51ab633bd8 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Databricks --- -- 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 + 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 3db4958ce9..e4cd9eaee3 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index b0cb402f51..83502418ed 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index e321608335..436df1663d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Postgres -- 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 + 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/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index e793ec07bb..60a094b8c4 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index d1a6367966..332a1bc9b2 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) 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/Postgres/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql index bbfe367e41..bfddb4a78f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql index b3aab0ff2b..da1a9518f2 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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 + 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql index 9c8e16b6b3..a603e2a363 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 13abbd386f..4b272126d7 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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 + 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 + 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/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index c546f8d7e5..61eec3aaa9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Postgres --- -- 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 + 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/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 91bd1ce2c9..68d512f46a 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 655a90ba4a..99dfa9690b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index d2225e0934..6b86be70cd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Redshift -- 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 + 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/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 91361265f4..96a312a85f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 0ac19b1a3d..3c9961de43 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) 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/Redshift/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql index b9778225fc..fe09118687 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql index 5b0894fa0a..51a8c0406d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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 + 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql index a9c9317585..ed5993961c 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 9d727697e0..85a1d5d2e1 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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 + 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 + 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/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 8c33b63fb3..7d01600236 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Redshift --- -- 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 + 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index c9793b14c7..849c390994 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index ee3f16a50d..2c6c6f261e 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 98954f84bf..43303bbd7d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Snowflake -- 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 + 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/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 1f0e70a8be..1ba1b0ca93 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 331e97ac60..987c491228 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) 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/Snowflake/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql index 2fe7ef70cd..e6f31bb81d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql index 7819cc490d..c384955899 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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 + 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql index 88e372e4b2..a7f9d92fe3 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 7f6e67f0db..7b68820464 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + 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/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 1f44f6f733..d3c510e166 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Snowflake --- -- 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 + 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index b2a37384b6..704c378706 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 4dd7001fd6..152a4d0ba8 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 98b9811d20..c787cb6c23 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Trino -- 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 + 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/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 5d71cfc2ea..ff3dfd9c8b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-03' AND timestamp '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 + 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(DAY_OF_WEEK 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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day + ) subq_9 + WHERE subq_9.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_10 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index ec034f8704..ec34f2218d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' - ) subq_14 + ) 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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_17 + subq_19.metric_time__day = subq_15.metric_time__day + WHERE subq_19.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql index 8b2da0017b..bea14ccbff 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql index 31148d821f..5a3579c4ae 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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 + 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 + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql index baef9e45ff..f18adc5925 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index f8f5f9dc09..7f85df947c 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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 + 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 + 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/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 636492a102..d9208e2fea 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Trino --- -- 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 + 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index fd38b34a28..fadf7d6cb1 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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 + 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 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 From fe9a711d24ccc5e2284a743962d0aafe64cd03b2 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 25 Nov 2024 12:00:15 -0800 Subject: [PATCH 8/8] Add query output tests for join to time spine metrics with custom grain filters --- .../query_output/test_fill_nulls_with_0.py | 62 + ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++++ 13 files changed, 6128 insertions(+) create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt diff --git a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py index b2e22ce13d..9cb93184b3 100644 --- a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py +++ b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py @@ -295,3 +295,65 @@ def test_join_to_time_spine_with_custom_grain_in_group_by( # noqa: D103 snapshot_str=query_result.result_df.text_format(), sql_engine=sql_client.sql_engine_type, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__martian_day",), + order_by_names=("metric_time__martian_day",), + where_constraints=["{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-08'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__day",), + order_by_names=("metric_time__day",), + where_constraints=["{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-08'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..64dffa1ece --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +METRIC_TIME__MARTIAN_DAY BOOKINGS_JOIN_TO_TIME_SPINE +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..d5ed44764d --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +METRIC_TIME__DAY BOOKINGS_JOIN_TO_TIME_SPINE +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None